﻿using CastingWellEquipmentGUI.Config;
using CastingWellEquipmentGUI.Dao;
using CastingWellEquipmentGUI.Model;
using CastingWellEquipmentGUI.Utils;
using CastingWellEquipmentGUI.ViewModel.Common.Command;
using CastingWellEquipmentGUI.ViewModel.Common.LogTool;
using CastingWellEquipmentGUI.ViewModel.Common.WindowsManager;
using Confluent.Kafka;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace CastingWellEquipmentGUI.ViewModel.Pages
{
    public class RecipeSelectionPageViewModel : ViewModelBase
    {
        //等待Kafaka改变标签值结果的消息
        private IConsumer<string, object> KafkaConsumerOfChangeValue = KafkaHelper.GetConsumerChangeValue();
        #region 选择
        /// <summary>
        /// 选择显示模型
        /// </summary>
        private RecipeTable _SelectViewModel;
        /// <summary>
        /// 选择显示模型
        /// </summary>
        public RecipeTable SelectViewModel
        {
            get { return _SelectViewModel; }
            set
            {
                _SelectViewModel = value;
                RaisePropertyChanged("SelectViewModel");
            }
        }

        /// <summary>
        /// 选择配方模型
        /// </summary>
        private RecipeTable _SelectRecipeModel;
        /// <summary>
        /// 选择配方模型
        /// </summary>
        public RecipeTable SelectRecipeModel
        {
            get { return _SelectRecipeModel; }
            set
            {
                _SelectRecipeModel = value;
                RaisePropertyChanged("SelectRecipeModel");
            }
        }

        /// <summary>
        /// 下载配方模型
        /// </summary>
        private RecipeTableByVerification _DownloadRecipeModel;
        /// <summary>
        /// 下载配方模型
        /// </summary>
        public RecipeTableByVerification DownloadRecipeModel
        {
            get { return _DownloadRecipeModel; }
            set
            {
                _DownloadRecipeModel = value;
                RaisePropertyChanged("DownloadRecipeModel");
            }
        }

        #endregion
        #region 分页使用
        /// <summary>
        /// 每页数量
        /// </summary>
        private int itemCount = 5;

        /// <summary>
        /// 总数量
        /// </summary>
        private int totalDataCount = 0;

        /// <summary>
        /// 总页数
        /// </summary>
        public int TotalPageNumber
        {
            get
            {
                int totalPageNumber = totalDataCount / itemCount;
                if (totalDataCount % itemCount > 0)
                {
                    totalPageNumber++;
                }
                return totalPageNumber;

            }
        }
        /// <summary>
        /// 总数据量
        /// </summary>
        public int TotalDataCount
        {
            get { return totalDataCount; }
            set
            {
                totalDataCount = value;
                RaisePropertyChanged("TotalDataCount");
                RaisePropertyChanged("TotalPageNumber");
            }
        }

        /// <summary>
        /// 当前所在页数
        /// </summary>
        private int _CurrentPageNumber = 1;
        /// <summary>
        /// 当前所在页数
        /// </summary>
        public int CurrentPageNumber
        {
            get { return _CurrentPageNumber; }
            set
            {
                _CurrentPageNumber = value;
                RaisePropertyChanged("CurrentPageNumber");
            }
        }
        /// <summary>
        /// 上一页页数
        /// </summary>
        public int PreviousPageNumber
        {
            get
            {
                if (_CurrentPageNumber - 1 > 0)
                {
                    return _CurrentPageNumber - 1;
                }
                return 1;
            }

        }
        /// <summary>
        /// 下一页页数
        /// </summary>
        public int NextPageNumber
        {
            get
            {
                if (_CurrentPageNumber + 1 <= TotalPageNumber)
                {
                    return _CurrentPageNumber + 1;
                }
                return _CurrentPageNumber;
            }

        }
        /// <summary>
        /// 分页页码集合
        /// </summary>
        private ObservableCollection<PageNumerModel> _PageNumers = new ObservableCollection<PageNumerModel>();
        /// <summary>
        /// 分页页码集合
        /// </summary>
        public ObservableCollection<PageNumerModel> PageNumers
        {
            get => _PageNumers;
            set
            {
                _PageNumers = value;
                RaisePropertyChanged("PageNumers");
            }
        }
        #endregion 分页使用
        #region 声明命令
        /// <summary>
        /// 铸造记录查看命令
        /// </summary>
        public DelegateCommand ShowCastingRecordCommand { get; set; }
        /// <summary>
        /// 搜索命令
        /// </summary>
        public DelegateCommand SeachCommand { get; set; }
        /// <summary>
        /// 跳转到指定页面命令
        /// </summary>
        public DelegateCommand GoToPageByNumberCommand { get; set; }
        /// <summary>
        /// 跳转到指定页面并关闭AllPageNumberPanel窗体命令
        /// </summary>
        public DelegateCommand GoToPageByNumberAndCloseAllPageNumberPanelCommand { get; set; }

        /// <summary>
        /// 显示更改到指定页面命令
        /// </summary>
        public DelegateCommand ChangeCurrentPageNumberCommand { get; set; }
        /// <summary>
        /// 显示配方选择页面命令
        /// </summary>
        public DelegateCommand ShowSelectPageCommand { get; set; }
        /// <summary>
        /// 添加到配方条件命令
        /// </summary>
        public DelegateCommand AddRecipeNameConditionsCommand { get; set; }
        /// <summary>
        /// 添加到合金条件命令
        /// </summary>
        public DelegateCommand AddAlloyConditionsCommand { get; set; }
        /// <summary>
        /// 添加到工艺搜索条件
        /// </summary>
        public DelegateCommand AddMoldTechConditionsCommand { get; set; }

        /// <summary>
        /// 添加到直径搜索条件
        /// </summary>
        public DelegateCommand AddMoldDiametersConditionsCommand { get; set; }
        /// <summary>
        /// 新增命令
        /// </summary>
        public DelegateCommand CreateCommand { get; set; }
        /// <summary>
        /// 编辑命令
        /// </summary>
        public DelegateCommand ShowEditModelCommand { get; set; }
        /// <summary>
        /// 显示删除模态窗体命令
        /// </summary>
        public DelegateCommand ShowDeleteModelCommand { get; set; }
        /// <summary>
        /// 选择配方命令
        /// </summary>
        public DelegateCommand SelectRecipeCommand { get; set; }
        /// <summary>
        /// 配方下载命令
        /// </summary>
        public DelegateCommand DownloadRecipeCommand { get; set; }
        /// <summary>
        /// 配方确认命令
        /// </summary>
        public DelegateCommand ConfirmRecipeCommand { get; set; }

        /// <summary>
        /// 初始化命令
        /// </summary>
        private void InitCommand()
        {
            ShowCastingRecordCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(ShowCastingRecordHandler)
            };
            CreateCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(CreateHandler)
            };
            ShowSelectPageCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(ShowSelectPageHandler)
            };

            AddRecipeNameConditionsCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(AddRecipeNameConditionsHandler)
            };

            AddAlloyConditionsCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(AddAlloyConditionsHandler)
            };

            AddMoldTechConditionsCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(AddMoldTechConditionsHandler)
            };

            AddMoldDiametersConditionsCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(AddMoldDiametersConditionsHandler)
            };

            GoToPageByNumberCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(GoToPageByNumberHandler)
            };

            GoToPageByNumberAndCloseAllPageNumberPanelCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(GoToPageByNumberAndCloseAllPageNumberPanelHandler)
            };

            ChangeCurrentPageNumberCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(ChangeCurrentPageNumberHandler)
            };

            SeachCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(SeachHandler)
            };

            ShowEditModelCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(ShowEditModelHandler)
            };

            ShowDeleteModelCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(ShowDeleteModelHandler)
            };

            SelectRecipeCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(SelectRecipeHandler)
            };

            DownloadRecipeCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(DownloadRecipeHandler)
            };
            ConfirmRecipeCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(ConfirmRecipeHandler)
            };
        }
        /// <summary>
        /// 铸造记录查看命令
        /// </summary>
        /// <param name="obj"></param>
        private void ShowCastingRecordHandler(object obj)
        {
            Messenger.Default.Send<string>("CastingRecordPage", "GoToPage");
        }

        /// <summary>
        /// 修改值
        /// </summary>
        /// <param name="DataTag"></param>
        /// <param name="value"></param>
        private void ToChangeTagData(Meta_Tag DataTag, float value)
        {
            Meta_Driver whereMeta_DriverObj = new Meta_Driver
            {
                TagID = DataTag.TagID
            };
            string sql = @"SELECT a.*,b.PlcModelName,c.BrandName,t.Address,t.DataType,t.TagID
                           FROM Meta_Tag t
                           LEFT JOIN Meta_Group d on d.GroupID = t.GroupID
                           LEFT JOIN Meta_Driver a on a.DriverID = d.DriverID
                           LEFT JOIN PlcModel b ON a.PlcModelId = b.PlcModelId
                           LEFT JOIN Brand c ON b.BrandId = c.BrandId
                           WHERE t.TagID = @TagID";
            Meta_Driver meta_Driver = DapperToolsGatewayServer.Query(sql, whereMeta_DriverObj);
            DeviceCommunication deviceCommunication = new DeviceCommunication();
            if (!deviceCommunication.SetTagValue(meta_Driver.BrandName,
                                             meta_Driver.PlcModelName,
                                             meta_Driver.IP,
                                             meta_Driver.Address,
                                             meta_Driver.DataType,
                                             value.ToString()))
            {
                MessageBox.Show("与PLC连接失败！", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
            }

            //string jsonStr = JsonConvert.SerializeObject(setTagValueMsg);
            //KafkaHelper.ProduceMessage(jsonStr);
            //int WaitingTime = 0;
            //while (true)
            //{
            //    Thread.Sleep(100);

            //    //开始消费
            //    var result = KafkaConsumerOfChangeValue.Consume();

            //    if (result.Message.Value != null)
            //    {
            //        //手动提交
            //        KafkaConsumerOfChangeValue.Commit(result);
            //        //获取消息内容
            //        string resultValue = result.Message.Value.ToString();
            //        break;
            //    }
            //    else
            //    {
            //        Thread.Sleep(900);
            //        WaitingTime++;
            //    }
            //    if (WaitingTime == 2)
            //    {
            //        break;
            //    }
            //}
        }
        /// <summary>
        /// 输入正常信号灯标签
        /// </summary>
        private Meta_Tag InputNormalTag = GetMeta_TagByRecipeSelectionsRecipeSelectionName("输入正常");
        /// <summary>
        /// 配方有效信号灯标签
        /// </summary>
        private Meta_Tag RecipeValidTag = GetMeta_TagByRecipeSelectionsRecipeSelectionName("配方有效");
        /// <summary>
        /// 已接受信号灯标签
        /// </summary>
        private Meta_Tag AcceptedTag = GetMeta_TagByRecipeSelectionsRecipeSelectionName("已接受");


        private static Meta_Tag GetMeta_TagByControlNameAndFormName(string formName, string controlName)
        {
            foreach (Role role in LogTool.CurrentUser.Roles)
            {
                foreach (Permissions permissions in role.Permissions)
                {
                    if (permissions.PForm != null && permissions.PForm.FormName == formName &&
                       permissions.PControl != null && permissions.PControl.ControlName == controlName
                        )
                    {

                        return GetMeta_TagById(permissions.PControl.Tag.Id);
                    }
                }
            }
            return null;
        }

        private static Meta_Tag GetMeta_TagByRecipeSelectionsRecipeSelectionName(string RecipeSelectionName)
        {
            RecipeSelection recipeSelectionWhere = new RecipeSelection();
            recipeSelectionWhere.RecipeSelectionName = RecipeSelectionName;
            RecipeSelection recipeSelection = DapperToolsThisSystem.Query<RecipeSelection>("select * from RecipeSelection where RecipeSelectionName = @RecipeSelectionName", recipeSelectionWhere);
            return GetMeta_TagById(recipeSelection.RecipeSelectionTagId);
        }


        private static Meta_Tag GetMeta_TagById(int Id)
        {
            Meta_Tag meta_Tag = new Meta_Tag
            {
                TagID = Id
            };
            return DapperToolsThisSystem.Query("SELECT * FROM DB_AlarmServer.dbo.Meta_Tag WHERE TagID = @TagID", meta_Tag);
        }
        /// <summary>
        /// 确认
        /// </summary>
        /// <param name="obj"></param>
        private void ConfirmRecipeHandler(object obj)
        {
            DownloadRecipeModel = LoadDownloadRecipeModel(SelectRecipeModel);

            //下载到PLC
            ToChangeTagData(DownloadRecipeModel.FRN_FRNTILTBACKOFFSET_StorageTag, DownloadRecipeModel.FRN_FRNTILTBACKOFFSET);
            ToChangeTagData(DownloadRecipeModel.FRN_FRNBATHTEMPSP_StorageTag, DownloadRecipeModel.FRN_FRNBATHTEMPSP);
            ToChangeTagData(DownloadRecipeModel.FRN_FRNBATHTEMPHILIM_StorageTag, DownloadRecipeModel.FRN_FRNBATHTEMPHILIM);
            ToChangeTagData(DownloadRecipeModel.FRN_FRNBATHTEMPLOLIM_StorageTag, DownloadRecipeModel.FRN_FRNBATHTEMPLOLIM);
            ToChangeTagData(DownloadRecipeModel.TGH_TROUGHTEMP_StorageTag, DownloadRecipeModel.TGH_TROUGHTEMP);
            ToChangeTagData(DownloadRecipeModel.ROD_RODSPEED_StorageTag, DownloadRecipeModel.ROD_RODSPEED);
            ToChangeTagData(DownloadRecipeModel.LEN_CASTLENGTH_StorageTag, DownloadRecipeModel.LEN_CASTLENGTH);
            ToChangeTagData(DownloadRecipeModel.MTL_DEGASTEMP_StorageTag, DownloadRecipeModel.MTL_DEGASTEMP);
            ToChangeTagData(DownloadRecipeModel.GAS_IDLECASTGAS_StorageTag, DownloadRecipeModel.GAS_IDLECASTGAS);
            ToChangeTagData(DownloadRecipeModel.GAS_STARTCASTGASLEN_StorageTag, DownloadRecipeModel.GAS_STARTCASTGASLEN);
            ToChangeTagData(DownloadRecipeModel.GAS_STARTCASTGAS_StorageTag, DownloadRecipeModel.GAS_STARTCASTGAS);
            ToChangeTagData(DownloadRecipeModel.GAS_BEGINRAMPDOWN_StorageTag, DownloadRecipeModel.GAS_BEGINRAMPDOWN);
            ToChangeTagData(DownloadRecipeModel.GAS_ENDRAMPDOWN_StorageTag, DownloadRecipeModel.GAS_ENDRAMPDOWN);
            ToChangeTagData(DownloadRecipeModel.GAS_RUNCASTGAS_StorageTag, DownloadRecipeModel.GAS_RUNCASTGAS);
            ToChangeTagData(DownloadRecipeModel.MSC_COOLDOWNTIME_StorageTag, DownloadRecipeModel.MSC_COOLDOWNTIME);
            ToChangeTagData(DownloadRecipeModel.SPD_PLTNHOLDTIME_StorageTag, DownloadRecipeModel.SPD_PLTNHOLDTIME);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOWSTART_StorageTag, DownloadRecipeModel.WTR_WTRFLOWSTART);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW1LEN_StorageTag, DownloadRecipeModel.WTR_WTRFLOW1LEN);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW2LEN_StorageTag, DownloadRecipeModel.WTR_WTRFLOW2LEN);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW3LEN_StorageTag, DownloadRecipeModel.WTR_WTRFLOW3LEN);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW4LEN_StorageTag, DownloadRecipeModel.WTR_WTRFLOW4LEN);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW5LEN_StorageTag, DownloadRecipeModel.WTR_WTRFLOW5LEN);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW6LEN_StorageTag, DownloadRecipeModel.WTR_WTRFLOW6LEN);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOWEND_StorageTag, DownloadRecipeModel.WTR_WTRFLOWEND);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRTEMPHILIMIT_StorageTag, DownloadRecipeModel.WTR_WTRTEMPHILIMIT);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRTEMPLOLIMIT_StorageTag, DownloadRecipeModel.WTR_WTRTEMPLOLIMIT);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW1_StorageTag, DownloadRecipeModel.WTR_WTRFLOW1);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW2_StorageTag, DownloadRecipeModel.WTR_WTRFLOW2);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW3_StorageTag, DownloadRecipeModel.WTR_WTRFLOW3);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW4_StorageTag, DownloadRecipeModel.WTR_WTRFLOW4);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW5_StorageTag, DownloadRecipeModel.WTR_WTRFLOW5);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW6_StorageTag, DownloadRecipeModel.WTR_WTRFLOW6);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD1LEN_StorageTag, DownloadRecipeModel.SPD_CASTSPD1LEN);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD2LEN_StorageTag, DownloadRecipeModel.SPD_CASTSPD2LEN);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD3LEN_StorageTag, DownloadRecipeModel.SPD_CASTSPD3LEN);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD4LEN_StorageTag, DownloadRecipeModel.SPD_CASTSPD4LEN);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD5LEN_StorageTag, DownloadRecipeModel.SPD_CASTSPD5LEN);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD6LEN_StorageTag, DownloadRecipeModel.SPD_CASTSPD6LEN);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPDSTART_StorageTag, DownloadRecipeModel.SPD_CASTSPDSTART);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD1_StorageTag, DownloadRecipeModel.SPD_CASTSPD1);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD2_StorageTag, DownloadRecipeModel.SPD_CASTSPD2);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD3_StorageTag, DownloadRecipeModel.SPD_CASTSPD3);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD4_StorageTag, DownloadRecipeModel.SPD_CASTSPD4);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD5_StorageTag, DownloadRecipeModel.SPD_CASTSPD5);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD6_StorageTag, DownloadRecipeModel.SPD_CASTSPD6);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPDEND_StorageTag, DownloadRecipeModel.SPD_CASTSPDEND);
            ToChangeTagData(DownloadRecipeModel.LUB_PULSELUBEPULSES_StorageTag, DownloadRecipeModel.LUB_PULSELUBEPULSES);
            ToChangeTagData(DownloadRecipeModel.LUB_PULSELUBEONTIME_StorageTag, DownloadRecipeModel.LUB_PULSELUBEONTIME);
            ToChangeTagData(DownloadRecipeModel.LUB_PULSELUBEOFFTIME_StorageTag, DownloadRecipeModel.LUB_PULSELUBEOFFTIME);
            ToChangeTagData(DownloadRecipeModel.LUB_PULSELUBECYCTIME_StorageTag, DownloadRecipeModel.LUB_PULSELUBECYCTIME);
            ToChangeTagData(DownloadRecipeModel.LUB_PULSELUBEPRESFIRE_StorageTag, DownloadRecipeModel.LUB_PULSELUBEPRESFIRE);
            ToChangeTagData(DownloadRecipeModel.LUB_PULSELUBEPRESRESET_StorageTag, DownloadRecipeModel.LUB_PULSELUBEPRESRESET);
            ToChangeTagData(DownloadRecipeModel.LUB_PULSELUBEPRESHOLD_StorageTag, DownloadRecipeModel.LUB_PULSELUBEPRESHOLD);


            DeviceCommunication deviceCommunication = new DeviceCommunication();
            Meta_Driver whereMeta_DriverObj = new Meta_Driver();
            whereMeta_DriverObj.TagID = AcceptedTag.TagID;
            string sql = @"SELECT a.*,b.PlcModelName,c.BrandName,t.Address,t.DataType,t.TagID
                           FROM Meta_Tag t
                           LEFT JOIN Meta_Group d on d.GroupID = t.GroupID
                           LEFT JOIN Meta_Driver a on a.DriverID = d.DriverID
                           LEFT JOIN PlcModel b ON a.PlcModelId = b.PlcModelId
                           LEFT JOIN Brand c ON b.BrandId = c.BrandId
                           WHERE t.TagID = @TagID";
            Meta_Driver meta_Driver = DapperToolsGatewayServer.Query(sql, whereMeta_DriverObj);
            //获取PLC输入接受
            //如果接受
            if (deviceCommunication.GetTagValue(meta_Driver.BrandName,
                                                meta_Driver.PlcModelName,
                                                meta_Driver.IP,
                                                meta_Driver.Address,
                                                meta_Driver.DataType).ToString().ToLower() == "true")
            {
                Button_Accepted = GreenBrush;
            }
            else
            {
                Button_Accepted = RedBrush;
            }
        }

        /// <summary>
        /// 配方下载名利处理器
        /// </summary>
        /// <param name="obj"></param>
        private void DownloadRecipeHandler(object obj)
        {
            DownloadRecipeModel = LoadDownloadRecipeModel(SelectRecipeModel);

            //下载到PLC
            ToChangeTagData(DownloadRecipeModel.FRN_FRNTILTBACKOFFSET_DataTag, DownloadRecipeModel.FRN_FRNTILTBACKOFFSET);
            ToChangeTagData(DownloadRecipeModel.FRN_FRNBATHTEMPSP_DataTag, DownloadRecipeModel.FRN_FRNBATHTEMPSP);
            ToChangeTagData(DownloadRecipeModel.FRN_FRNBATHTEMPHILIM_DataTag, DownloadRecipeModel.FRN_FRNBATHTEMPHILIM);
            ToChangeTagData(DownloadRecipeModel.FRN_FRNBATHTEMPLOLIM_DataTag, DownloadRecipeModel.FRN_FRNBATHTEMPLOLIM);
            ToChangeTagData(DownloadRecipeModel.TGH_TROUGHTEMP_DataTag, DownloadRecipeModel.TGH_TROUGHTEMP);
            ToChangeTagData(DownloadRecipeModel.ROD_RODSPEED_DataTag, DownloadRecipeModel.ROD_RODSPEED);
            ToChangeTagData(DownloadRecipeModel.LEN_CASTLENGTH_DataTag, DownloadRecipeModel.LEN_CASTLENGTH);
            ToChangeTagData(DownloadRecipeModel.MTL_DEGASTEMP_DataTag, DownloadRecipeModel.MTL_DEGASTEMP);
            ToChangeTagData(DownloadRecipeModel.GAS_IDLECASTGAS_DataTag, DownloadRecipeModel.GAS_IDLECASTGAS);
            ToChangeTagData(DownloadRecipeModel.GAS_STARTCASTGASLEN_DataTag, DownloadRecipeModel.GAS_STARTCASTGASLEN);
            ToChangeTagData(DownloadRecipeModel.GAS_STARTCASTGAS_DataTag, DownloadRecipeModel.GAS_STARTCASTGAS);
            ToChangeTagData(DownloadRecipeModel.GAS_BEGINRAMPDOWN_DataTag, DownloadRecipeModel.GAS_BEGINRAMPDOWN);
            ToChangeTagData(DownloadRecipeModel.GAS_ENDRAMPDOWN_DataTag, DownloadRecipeModel.GAS_ENDRAMPDOWN);
            ToChangeTagData(DownloadRecipeModel.GAS_RUNCASTGAS_DataTag, DownloadRecipeModel.GAS_RUNCASTGAS);
            ToChangeTagData(DownloadRecipeModel.MSC_COOLDOWNTIME_DataTag, DownloadRecipeModel.MSC_COOLDOWNTIME);
            ToChangeTagData(DownloadRecipeModel.SPD_PLTNHOLDTIME_DataTag, DownloadRecipeModel.SPD_PLTNHOLDTIME);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOWSTART_DataTag, DownloadRecipeModel.WTR_WTRFLOWSTART);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW1LEN_DataTag, DownloadRecipeModel.WTR_WTRFLOW1LEN);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW2LEN_DataTag, DownloadRecipeModel.WTR_WTRFLOW2LEN);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW3LEN_DataTag, DownloadRecipeModel.WTR_WTRFLOW3LEN);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW4LEN_DataTag, DownloadRecipeModel.WTR_WTRFLOW4LEN);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW5LEN_DataTag, DownloadRecipeModel.WTR_WTRFLOW5LEN);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW6LEN_DataTag, DownloadRecipeModel.WTR_WTRFLOW6LEN);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOWEND_DataTag, DownloadRecipeModel.WTR_WTRFLOWEND);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRTEMPHILIMIT_DataTag, DownloadRecipeModel.WTR_WTRTEMPHILIMIT);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRTEMPLOLIMIT_DataTag, DownloadRecipeModel.WTR_WTRTEMPLOLIMIT);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW1_DataTag, DownloadRecipeModel.WTR_WTRFLOW1);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW2_DataTag, DownloadRecipeModel.WTR_WTRFLOW2);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW3_DataTag, DownloadRecipeModel.WTR_WTRFLOW3);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW4_DataTag, DownloadRecipeModel.WTR_WTRFLOW4);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW5_DataTag, DownloadRecipeModel.WTR_WTRFLOW5);
            ToChangeTagData(DownloadRecipeModel.WTR_WTRFLOW6_DataTag, DownloadRecipeModel.WTR_WTRFLOW6);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD1LEN_DataTag, DownloadRecipeModel.SPD_CASTSPD1LEN);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD2LEN_DataTag, DownloadRecipeModel.SPD_CASTSPD2LEN);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD3LEN_DataTag, DownloadRecipeModel.SPD_CASTSPD3LEN);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD4LEN_DataTag, DownloadRecipeModel.SPD_CASTSPD4LEN);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD5LEN_DataTag, DownloadRecipeModel.SPD_CASTSPD5LEN);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD6LEN_DataTag, DownloadRecipeModel.SPD_CASTSPD6LEN);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPDSTART_DataTag, DownloadRecipeModel.SPD_CASTSPDSTART);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD1_DataTag, DownloadRecipeModel.SPD_CASTSPD1);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD2_DataTag, DownloadRecipeModel.SPD_CASTSPD2);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD3_DataTag, DownloadRecipeModel.SPD_CASTSPD3);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD4_DataTag, DownloadRecipeModel.SPD_CASTSPD4);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD5_DataTag, DownloadRecipeModel.SPD_CASTSPD5);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPD6_DataTag, DownloadRecipeModel.SPD_CASTSPD6);
            ToChangeTagData(DownloadRecipeModel.SPD_CASTSPDEND_DataTag, DownloadRecipeModel.SPD_CASTSPDEND);
            ToChangeTagData(DownloadRecipeModel.LUB_PULSELUBEPULSES_DataTag, DownloadRecipeModel.LUB_PULSELUBEPULSES);
            ToChangeTagData(DownloadRecipeModel.LUB_PULSELUBEONTIME_DataTag, DownloadRecipeModel.LUB_PULSELUBEONTIME);
            ToChangeTagData(DownloadRecipeModel.LUB_PULSELUBEOFFTIME_DataTag, DownloadRecipeModel.LUB_PULSELUBEOFFTIME);
            ToChangeTagData(DownloadRecipeModel.LUB_PULSELUBECYCTIME_DataTag, DownloadRecipeModel.LUB_PULSELUBECYCTIME);
            ToChangeTagData(DownloadRecipeModel.LUB_PULSELUBEPRESFIRE_DataTag, DownloadRecipeModel.LUB_PULSELUBEPRESFIRE);
            ToChangeTagData(DownloadRecipeModel.LUB_PULSELUBEPRESRESET_DataTag, DownloadRecipeModel.LUB_PULSELUBEPRESRESET);
            ToChangeTagData(DownloadRecipeModel.LUB_PULSELUBEPRESHOLD_DataTag, DownloadRecipeModel.LUB_PULSELUBEPRESHOLD);



            Meta_Driver whereMeta_DriverObj = new Meta_Driver();
            whereMeta_DriverObj.TagID = InputNormalTag.TagID;
            string sql = @"SELECT a.*,b.PlcModelName,c.BrandName,t.Address,t.DataType,t.TagID
                           FROM Meta_Tag t
                           LEFT JOIN Meta_Group d on d.GroupID = t.GroupID
                           LEFT JOIN Meta_Driver a on a.DriverID = d.DriverID
                           LEFT JOIN PlcModel b ON a.PlcModelId = b.PlcModelId
                           LEFT JOIN Brand c ON b.BrandId = c.BrandId
                           WHERE t.TagID = @TagID";
            Meta_Driver meta_Driver = DapperToolsGatewayServer.Query(sql, whereMeta_DriverObj);

            DeviceCommunication deviceCommunication = new DeviceCommunication();
            //如果输入正常
            if (deviceCommunication.GetTagValue(meta_Driver.BrandName,
                                                meta_Driver.PlcModelName,
                                                meta_Driver.IP,
                                                meta_Driver.Address,
                                                meta_Driver.DataType).ToString().ToLower() == "true")
            {
                Button_InputNormal = GreenBrush;
            }
            else
            {
                Button_InputNormal = RedBrush;
            }
            whereMeta_DriverObj = new Meta_Driver();
            whereMeta_DriverObj.TagID = RecipeValidTag.TagID;
            sql = @"SELECT a.*,b.PlcModelName,c.BrandName,t.Address,t.DataType,t.TagID
                           FROM Meta_Tag t
                           LEFT JOIN Meta_Group d on d.GroupID = t.GroupID
                           LEFT JOIN Meta_Driver a on a.DriverID = d.DriverID
                           LEFT JOIN PlcModel b ON a.PlcModelId = b.PlcModelId
                           LEFT JOIN Brand c ON b.BrandId = c.BrandId
                           WHERE t.TagID = @TagID";
            meta_Driver = DapperToolsGatewayServer.Query(sql, whereMeta_DriverObj);
            //获取PLC输入是否有效
            //如果有效
            if (deviceCommunication.GetTagValue(meta_Driver.BrandName,
                                                meta_Driver.PlcModelName,
                                                meta_Driver.IP,
                                                meta_Driver.Address,
                                                meta_Driver.DataType).ToString().ToLower() == "true")
            {
                Button_RecipeValid = GreenBrush;
            }
            else
            {
                Button_RecipeValid = RedBrush;
            }



        }
        private Meta_Tag GetTagByItemName(string ItemName)
        {
            Meta_Tag meta_Tag = new Meta_Tag();
            string sql = @"SELECT * 
                          FROM DB_AlarmServer.dbo.Meta_Tag 
                          WHERE TagID = (
                                    SELECT TagId 
                                    FROM DB_CWEGUI.dbo.RecipeVerificationConfig
                                    WHERE ItemName = '" + ItemName + @"'
                          )";
            return DapperToolsThisSystem.Query(sql, meta_Tag);
        }
        private Meta_Tag GetDataTagByItemName(string ItemName)
        {
            Meta_Tag meta_Tag = new Meta_Tag();
            string sql = @"SELECT * 
                          FROM DB_AlarmServer.dbo.Meta_Tag 
                          WHERE TagID = (
                                    SELECT DataTagId 
                                    FROM DB_CWEGUI.dbo.RecipeVerificationConfig
                                    WHERE ItemName = '" + ItemName + @"'
                          )";
            return DapperToolsThisSystem.Query(sql, meta_Tag);
        }
        private Meta_Tag GetStorageTagByItemName(string ItemName)
        {
            Meta_Tag meta_Tag = new Meta_Tag();
            string sql = @"SELECT * 
                          FROM DB_AlarmServer.dbo.Meta_Tag 
                          WHERE TagID = (
                                    SELECT StorageTagId 
                                    FROM DB_CWEGUI.dbo.RecipeVerificationConfig
                                    WHERE ItemName = '" + ItemName + @"'
                          )";
            return DapperToolsThisSystem.Query(sql, meta_Tag);
        }
        /// <summary>
        /// 初始化标签
        /// </summary>
        private void InitTag(ref RecipeTableByVerification recipeTableByVerification)
        {
            recipeTableByVerification.FRN_FRNTILTBACKOFFSET_Tag = GetTagByItemName("FRN_FRNTILTBACKOFFSET");
            recipeTableByVerification.FRN_FRNTILTBACKOFFSET_DataTag = GetDataTagByItemName("FRN_FRNTILTBACKOFFSET");
            recipeTableByVerification.FRN_FRNTILTBACKOFFSET_StorageTag = GetStorageTagByItemName("FRN_FRNTILTBACKOFFSET");

            recipeTableByVerification.FRN_FRNBATHTEMPSP_Tag = GetTagByItemName("FRN_FRNBATHTEMPSP");
            recipeTableByVerification.FRN_FRNBATHTEMPSP_DataTag = GetDataTagByItemName("FRN_FRNBATHTEMPSP");
            recipeTableByVerification.FRN_FRNBATHTEMPSP_StorageTag = GetStorageTagByItemName("FRN_FRNBATHTEMPSP");

            recipeTableByVerification.FRN_FRNBATHTEMPHILIM_Tag = GetTagByItemName("FRN_FRNBATHTEMPHILIM");
            recipeTableByVerification.FRN_FRNBATHTEMPHILIM_DataTag = GetDataTagByItemName("FRN_FRNBATHTEMPHILIM");
            recipeTableByVerification.FRN_FRNBATHTEMPHILIM_StorageTag = GetStorageTagByItemName("FRN_FRNBATHTEMPHILIM");

            recipeTableByVerification.FRN_FRNBATHTEMPLOLIM_Tag = GetTagByItemName("FRN_FRNBATHTEMPLOLIM");
            recipeTableByVerification.FRN_FRNBATHTEMPLOLIM_DataTag = GetDataTagByItemName("FRN_FRNBATHTEMPLOLIM");
            recipeTableByVerification.FRN_FRNBATHTEMPLOLIM_StorageTag = GetStorageTagByItemName("FRN_FRNBATHTEMPLOLIM");

            recipeTableByVerification.TGH_TROUGHTEMP_Tag = GetTagByItemName("TGH_TROUGHTEMP");
            recipeTableByVerification.TGH_TROUGHTEMP_DataTag = GetDataTagByItemName("TGH_TROUGHTEMP");
            recipeTableByVerification.TGH_TROUGHTEMP_StorageTag = GetStorageTagByItemName("TGH_TROUGHTEMP");


            recipeTableByVerification.ROD_RODSPEED_Tag = GetTagByItemName("ROD_RODSPEED");
            recipeTableByVerification.ROD_RODSPEED_DataTag = GetDataTagByItemName("ROD_RODSPEED");
            recipeTableByVerification.ROD_RODSPEED_StorageTag = GetStorageTagByItemName("ROD_RODSPEED");


            recipeTableByVerification.LEN_CASTLENGTH_Tag = GetTagByItemName("LEN_CASTLENGTH");
            recipeTableByVerification.LEN_CASTLENGTH_DataTag = GetDataTagByItemName("LEN_CASTLENGTH");
            recipeTableByVerification.LEN_CASTLENGTH_StorageTag = GetStorageTagByItemName("LEN_CASTLENGTH");

            recipeTableByVerification.MTL_DEGASTEMP_Tag = GetTagByItemName("MTL_DEGASTEMP");
            recipeTableByVerification.MTL_DEGASTEMP_DataTag = GetDataTagByItemName("MTL_DEGASTEMP");
            recipeTableByVerification.MTL_DEGASTEMP_StorageTag = GetStorageTagByItemName("MTL_DEGASTEMP");

            recipeTableByVerification.GAS_IDLECASTGAS_Tag = GetTagByItemName("GAS_IDLECASTGAS");
            recipeTableByVerification.GAS_IDLECASTGAS_DataTag = GetDataTagByItemName("GAS_IDLECASTGAS");
            recipeTableByVerification.GAS_IDLECASTGAS_StorageTag = GetStorageTagByItemName("GAS_IDLECASTGAS");

            recipeTableByVerification.GAS_STARTCASTGASLEN_Tag = GetTagByItemName("GAS_STARTCASTGASLEN");
            recipeTableByVerification.GAS_STARTCASTGASLEN_DataTag = GetDataTagByItemName("GAS_STARTCASTGASLEN");
            recipeTableByVerification.GAS_STARTCASTGASLEN_StorageTag = GetStorageTagByItemName("GAS_STARTCASTGASLEN");

            recipeTableByVerification.GAS_STARTCASTGAS_Tag = GetTagByItemName("GAS_STARTCASTGAS");
            recipeTableByVerification.GAS_STARTCASTGAS_DataTag = GetDataTagByItemName("GAS_STARTCASTGAS");
            recipeTableByVerification.GAS_STARTCASTGAS_StorageTag = GetStorageTagByItemName("GAS_STARTCASTGAS");

            recipeTableByVerification.GAS_BEGINRAMPDOWN_Tag = GetTagByItemName("GAS_BEGINRAMPDOWN");
            recipeTableByVerification.GAS_BEGINRAMPDOWN_DataTag = GetDataTagByItemName("GAS_BEGINRAMPDOWN");
            recipeTableByVerification.GAS_BEGINRAMPDOWN_StorageTag = GetStorageTagByItemName("GAS_BEGINRAMPDOWN");

            recipeTableByVerification.GAS_ENDRAMPDOWN_Tag = GetTagByItemName("GAS_ENDRAMPDOWN");
            recipeTableByVerification.GAS_ENDRAMPDOWN_DataTag = GetDataTagByItemName("GAS_ENDRAMPDOWN");
            recipeTableByVerification.GAS_ENDRAMPDOWN_StorageTag = GetStorageTagByItemName("GAS_ENDRAMPDOWN");

            recipeTableByVerification.GAS_RUNCASTGAS_Tag = GetTagByItemName("GAS_RUNCASTGAS");
            recipeTableByVerification.GAS_RUNCASTGAS_DataTag = GetDataTagByItemName("GAS_RUNCASTGAS");
            recipeTableByVerification.GAS_RUNCASTGAS_StorageTag = GetStorageTagByItemName("GAS_RUNCASTGAS");

            recipeTableByVerification.MSC_COOLDOWNTIME_Tag = GetTagByItemName("MSC_COOLDOWNTIME");
            recipeTableByVerification.MSC_COOLDOWNTIME_DataTag = GetDataTagByItemName("MSC_COOLDOWNTIME");
            recipeTableByVerification.MSC_COOLDOWNTIME_StorageTag = GetStorageTagByItemName("MSC_COOLDOWNTIME");

            recipeTableByVerification.SPD_PLTNHOLDTIME_Tag = GetTagByItemName("SPD_PLTNHOLDTIME");
            recipeTableByVerification.SPD_PLTNHOLDTIME_DataTag = GetDataTagByItemName("SPD_PLTNHOLDTIME");
            recipeTableByVerification.SPD_PLTNHOLDTIME_StorageTag = GetStorageTagByItemName("SPD_PLTNHOLDTIME");

            recipeTableByVerification.WTR_WTRFLOWSTART_Tag = GetTagByItemName("WTR_WTRFLOWSTART");
            recipeTableByVerification.WTR_WTRFLOWSTART_DataTag = GetDataTagByItemName("WTR_WTRFLOWSTART");
            recipeTableByVerification.WTR_WTRFLOWSTART_StorageTag = GetStorageTagByItemName("WTR_WTRFLOWSTART");

            recipeTableByVerification.WTR_WTRFLOW1_Tag = GetTagByItemName("WTR_WTRFLOW1");
            recipeTableByVerification.WTR_WTRFLOW1_DataTag = GetDataTagByItemName("WTR_WTRFLOW1");
            recipeTableByVerification.WTR_WTRFLOW1_StorageTag = GetStorageTagByItemName("WTR_WTRFLOW1");

            recipeTableByVerification.WTR_WTRFLOW2_Tag = GetTagByItemName("WTR_WTRFLOW2");
            recipeTableByVerification.WTR_WTRFLOW2_DataTag = GetDataTagByItemName("WTR_WTRFLOW2");
            recipeTableByVerification.WTR_WTRFLOW2_StorageTag = GetStorageTagByItemName("WTR_WTRFLOW2");

            recipeTableByVerification.WTR_WTRFLOW3_Tag = GetTagByItemName("WTR_WTRFLOW3");
            recipeTableByVerification.WTR_WTRFLOW3_DataTag = GetDataTagByItemName("WTR_WTRFLOW3");
            recipeTableByVerification.WTR_WTRFLOW3_StorageTag = GetStorageTagByItemName("WTR_WTRFLOW3");

            recipeTableByVerification.WTR_WTRFLOW4_Tag = GetTagByItemName("WTR_WTRFLOW4");
            recipeTableByVerification.WTR_WTRFLOW4_DataTag = GetDataTagByItemName("WTR_WTRFLOW4");
            recipeTableByVerification.WTR_WTRFLOW4_StorageTag = GetStorageTagByItemName("WTR_WTRFLOW4");

            recipeTableByVerification.WTR_WTRFLOW5_Tag = GetTagByItemName("WTR_WTRFLOW5");
            recipeTableByVerification.WTR_WTRFLOW5_DataTag = GetDataTagByItemName("WTR_WTRFLOW5");
            recipeTableByVerification.WTR_WTRFLOW5_StorageTag = GetStorageTagByItemName("WTR_WTRFLOW5");

            recipeTableByVerification.WTR_WTRFLOW6_Tag = GetTagByItemName("WTR_WTRFLOW6");
            recipeTableByVerification.WTR_WTRFLOW6_DataTag = GetDataTagByItemName("WTR_WTRFLOW6");
            recipeTableByVerification.WTR_WTRFLOW6_StorageTag = GetStorageTagByItemName("WTR_WTRFLOW6");

            recipeTableByVerification.WTR_WTRFLOW1LEN_Tag = GetTagByItemName("WTR_WTRFLOW1LEN");
            recipeTableByVerification.WTR_WTRFLOW1LEN_DataTag = GetDataTagByItemName("WTR_WTRFLOW1LEN");
            recipeTableByVerification.WTR_WTRFLOW1LEN_StorageTag = GetStorageTagByItemName("WTR_WTRFLOW1LEN");

            recipeTableByVerification.WTR_WTRFLOW2LEN_Tag = GetTagByItemName("WTR_WTRFLOW2LEN");
            recipeTableByVerification.WTR_WTRFLOW2LEN_DataTag = GetDataTagByItemName("WTR_WTRFLOW2LEN");
            recipeTableByVerification.WTR_WTRFLOW2LEN_StorageTag = GetStorageTagByItemName("WTR_WTRFLOW2LEN");

            recipeTableByVerification.WTR_WTRFLOW3LEN_Tag = GetTagByItemName("WTR_WTRFLOW3LEN");
            recipeTableByVerification.WTR_WTRFLOW3LEN_DataTag = GetDataTagByItemName("WTR_WTRFLOW3LEN");
            recipeTableByVerification.WTR_WTRFLOW3LEN_StorageTag = GetStorageTagByItemName("WTR_WTRFLOW3LEN");

            recipeTableByVerification.WTR_WTRFLOW4LEN_Tag = GetTagByItemName("WTR_WTRFLOW4LEN");
            recipeTableByVerification.WTR_WTRFLOW4LEN_DataTag = GetDataTagByItemName("WTR_WTRFLOW4LEN");
            recipeTableByVerification.WTR_WTRFLOW4LEN_StorageTag = GetStorageTagByItemName("WTR_WTRFLOW4LEN");

            recipeTableByVerification.WTR_WTRFLOW5LEN_Tag = GetTagByItemName("WTR_WTRFLOW5LEN");
            recipeTableByVerification.WTR_WTRFLOW5LEN_DataTag = GetDataTagByItemName("WTR_WTRFLOW5LEN");
            recipeTableByVerification.WTR_WTRFLOW5LEN_StorageTag = GetStorageTagByItemName("WTR_WTRFLOW5LEN");

            recipeTableByVerification.WTR_WTRFLOW6LEN_Tag = GetTagByItemName("WTR_WTRFLOW6LEN");
            recipeTableByVerification.WTR_WTRFLOW6LEN_DataTag = GetDataTagByItemName("WTR_WTRFLOW6LEN");
            recipeTableByVerification.WTR_WTRFLOW6LEN_StorageTag = GetStorageTagByItemName("WTR_WTRFLOW6LEN");

            recipeTableByVerification.WTR_WTRFLOWEND_Tag = GetTagByItemName("WTR_WTRFLOWEND");
            recipeTableByVerification.WTR_WTRFLOWEND_DataTag = GetDataTagByItemName("WTR_WTRFLOWEND");
            recipeTableByVerification.WTR_WTRFLOWEND_StorageTag = GetStorageTagByItemName("WTR_WTRFLOWEND");

            recipeTableByVerification.WTR_WTRTEMPHILIMIT_Tag = GetTagByItemName("WTR_WTRTEMPHILIMIT");
            recipeTableByVerification.WTR_WTRTEMPHILIMIT_DataTag = GetDataTagByItemName("WTR_WTRTEMPHILIMIT");
            recipeTableByVerification.WTR_WTRTEMPHILIMIT_StorageTag = GetStorageTagByItemName("WTR_WTRTEMPHILIMIT");

            recipeTableByVerification.WTR_WTRTEMPLOLIMIT_Tag = GetTagByItemName("WTR_WTRTEMPLOLIMIT");
            recipeTableByVerification.WTR_WTRTEMPLOLIMIT_DataTag = GetDataTagByItemName("WTR_WTRTEMPLOLIMIT");
            recipeTableByVerification.WTR_WTRTEMPLOLIMIT_StorageTag = GetStorageTagByItemName("WTR_WTRTEMPLOLIMIT");

            recipeTableByVerification.SPD_CASTSPD1LEN_Tag = GetTagByItemName("SPD_CASTSPD1LEN");
            recipeTableByVerification.SPD_CASTSPD1LEN_DataTag = GetDataTagByItemName("SPD_CASTSPD1LEN");
            recipeTableByVerification.SPD_CASTSPD1LEN_StorageTag = GetStorageTagByItemName("SPD_CASTSPD1LEN");

            recipeTableByVerification.SPD_CASTSPD2LEN_Tag = GetTagByItemName("SPD_CASTSPD2LEN");
            recipeTableByVerification.SPD_CASTSPD2LEN_DataTag = GetDataTagByItemName("SPD_CASTSPD2LEN");
            recipeTableByVerification.SPD_CASTSPD2LEN_StorageTag = GetStorageTagByItemName("SPD_CASTSPD2LEN");

            recipeTableByVerification.SPD_CASTSPD3LEN_Tag = GetTagByItemName("SPD_CASTSPD3LEN");
            recipeTableByVerification.SPD_CASTSPD3LEN_DataTag = GetDataTagByItemName("SPD_CASTSPD3LEN");
            recipeTableByVerification.SPD_CASTSPD3LEN_StorageTag = GetStorageTagByItemName("SPD_CASTSPD3LEN");

            recipeTableByVerification.SPD_CASTSPD4LEN_Tag = GetTagByItemName("SPD_CASTSPD4LEN");
            recipeTableByVerification.SPD_CASTSPD4LEN_DataTag = GetDataTagByItemName("SPD_CASTSPD4LEN");
            recipeTableByVerification.SPD_CASTSPD4LEN_StorageTag = GetStorageTagByItemName("SPD_CASTSPD4LEN");

            recipeTableByVerification.SPD_CASTSPD5LEN_Tag = GetTagByItemName("SPD_CASTSPD5LEN");
            recipeTableByVerification.SPD_CASTSPD5LEN_DataTag = GetDataTagByItemName("SPD_CASTSPD5LEN");
            recipeTableByVerification.SPD_CASTSPD5LEN_StorageTag = GetStorageTagByItemName("SPD_CASTSPD5LEN");

            recipeTableByVerification.SPD_CASTSPD6LEN_Tag = GetTagByItemName("SPD_CASTSPD6LEN");
            recipeTableByVerification.SPD_CASTSPD6LEN_DataTag = GetDataTagByItemName("SPD_CASTSPD6LEN");
            recipeTableByVerification.SPD_CASTSPD6LEN_StorageTag = GetStorageTagByItemName("SPD_CASTSPD6LEN");

            recipeTableByVerification.SPD_CASTSPDSTART_Tag = GetTagByItemName("SPD_CASTSPDSTART");
            recipeTableByVerification.SPD_CASTSPDSTART_DataTag = GetDataTagByItemName("SPD_CASTSPDSTART");
            recipeTableByVerification.SPD_CASTSPDSTART_StorageTag = GetStorageTagByItemName("SPD_CASTSPDSTART");

            recipeTableByVerification.SPD_CASTSPD1_Tag = GetTagByItemName("SPD_CASTSPD1");
            recipeTableByVerification.SPD_CASTSPD1_DataTag = GetDataTagByItemName("SPD_CASTSPD1");
            recipeTableByVerification.SPD_CASTSPD1_StorageTag = GetStorageTagByItemName("SPD_CASTSPD1");

            recipeTableByVerification.SPD_CASTSPD2_Tag = GetTagByItemName("SPD_CASTSPD2");
            recipeTableByVerification.SPD_CASTSPD2_DataTag = GetDataTagByItemName("SPD_CASTSPD2");
            recipeTableByVerification.SPD_CASTSPD2_StorageTag = GetStorageTagByItemName("SPD_CASTSPD2");

            recipeTableByVerification.SPD_CASTSPD3_Tag = GetTagByItemName("SPD_CASTSPD3");
            recipeTableByVerification.SPD_CASTSPD3_DataTag = GetDataTagByItemName("SPD_CASTSPD3");
            recipeTableByVerification.SPD_CASTSPD3_StorageTag = GetStorageTagByItemName("SPD_CASTSPD3");

            recipeTableByVerification.SPD_CASTSPD4_Tag = GetTagByItemName("SPD_CASTSPD4");
            recipeTableByVerification.SPD_CASTSPD4_DataTag = GetDataTagByItemName("SPD_CASTSPD4");
            recipeTableByVerification.SPD_CASTSPD4_StorageTag = GetStorageTagByItemName("SPD_CASTSPD4");

            recipeTableByVerification.SPD_CASTSPD5_Tag = GetTagByItemName("SPD_CASTSPD5");
            recipeTableByVerification.SPD_CASTSPD5_DataTag = GetDataTagByItemName("SPD_CASTSPD5");
            recipeTableByVerification.SPD_CASTSPD5_StorageTag = GetStorageTagByItemName("SPD_CASTSPD5");

            recipeTableByVerification.SPD_CASTSPD6_Tag = GetTagByItemName("SPD_CASTSPD6");
            recipeTableByVerification.SPD_CASTSPD6_DataTag = GetDataTagByItemName("SPD_CASTSPD6");
            recipeTableByVerification.SPD_CASTSPD6_StorageTag = GetStorageTagByItemName("SPD_CASTSPD6");

            recipeTableByVerification.SPD_CASTSPDEND_Tag = GetTagByItemName("SPD_CASTSPDEND");
            recipeTableByVerification.SPD_CASTSPDEND_DataTag = GetDataTagByItemName("SPD_CASTSPDEND");
            recipeTableByVerification.SPD_CASTSPDEND_StorageTag = GetStorageTagByItemName("SPD_CASTSPDEND");

            recipeTableByVerification.LUB_PULSELUBEPULSES_Tag = GetTagByItemName("LUB_PULSELUBEPULSES");
            recipeTableByVerification.LUB_PULSELUBEPULSES_DataTag = GetDataTagByItemName("LUB_PULSELUBEPULSES");
            recipeTableByVerification.LUB_PULSELUBEPULSES_StorageTag = GetStorageTagByItemName("LUB_PULSELUBEPULSES");

            recipeTableByVerification.LUB_PULSELUBEONTIME_Tag = GetTagByItemName("LUB_PULSELUBEONTIME");
            recipeTableByVerification.LUB_PULSELUBEONTIME_DataTag = GetDataTagByItemName("LUB_PULSELUBEONTIME");
            recipeTableByVerification.LUB_PULSELUBEONTIME_StorageTag = GetStorageTagByItemName("LUB_PULSELUBEONTIME");

            recipeTableByVerification.LUB_PULSELUBEOFFTIME_Tag = GetTagByItemName("LUB_PULSELUBEOFFTIME");
            recipeTableByVerification.LUB_PULSELUBEOFFTIME_DataTag = GetDataTagByItemName("LUB_PULSELUBEOFFTIME");
            recipeTableByVerification.LUB_PULSELUBEOFFTIME_StorageTag = GetStorageTagByItemName("LUB_PULSELUBEOFFTIME");

            recipeTableByVerification.LUB_PULSELUBECYCTIME_Tag = GetTagByItemName("LUB_PULSELUBECYCTIME");
            recipeTableByVerification.LUB_PULSELUBECYCTIME_DataTag = GetDataTagByItemName("LUB_PULSELUBECYCTIME");
            recipeTableByVerification.LUB_PULSELUBECYCTIME_StorageTag = GetStorageTagByItemName("LUB_PULSELUBECYCTIME");

            recipeTableByVerification.LUB_PULSELUBEPRESFIRE_Tag = GetTagByItemName("LUB_PULSELUBEPRESFIRE");
            recipeTableByVerification.LUB_PULSELUBEPRESFIRE_DataTag = GetDataTagByItemName("LUB_PULSELUBEPRESFIRE");
            recipeTableByVerification.LUB_PULSELUBEPRESFIRE_StorageTag = GetStorageTagByItemName("LUB_PULSELUBEPRESFIRE");

            recipeTableByVerification.LUB_PULSELUBEPRESRESET_Tag = GetTagByItemName("LUB_PULSELUBEPRESRESET");
            recipeTableByVerification.LUB_PULSELUBEPRESRESET_DataTag = GetDataTagByItemName("LUB_PULSELUBEPRESRESET");
            recipeTableByVerification.LUB_PULSELUBEPRESRESET_StorageTag = GetStorageTagByItemName("LUB_PULSELUBEPRESRESET");

            recipeTableByVerification.LUB_PULSELUBEPRESHOLD_Tag = GetTagByItemName("LUB_PULSELUBEPRESHOLD");
            recipeTableByVerification.LUB_PULSELUBEPRESHOLD_DataTag = GetDataTagByItemName("LUB_PULSELUBEPRESHOLD");
            recipeTableByVerification.LUB_PULSELUBEPRESHOLD_StorageTag = GetStorageTagByItemName("LUB_PULSELUBEPRESHOLD");

        }
        private RecipeTableByVerification LoadDownloadRecipeModel(RecipeTable recipeTable)
        {
            RecipeTableByVerification recipeTableByVerification = new RecipeTableByVerification
            {
                RecipeId = recipeTable.RecipeId,
                RecipeName = recipeTable.RecipeName,
                RecipeNameStr = recipeTable.RecipeNameStr,
                FRN_FRNBATHTEMPHILIM = recipeTable.FRN_FRNBATHTEMPHILIM,
                FRN_FRNBATHTEMPLOLIM = recipeTable.FRN_FRNBATHTEMPLOLIM,
                FRN_FRNBATHTEMPSP = recipeTable.FRN_FRNBATHTEMPSP,
                FRN_FRNTILTBACKOFFSET = recipeTable.FRN_FRNTILTBACKOFFSET,
                GAS_BEGINRAMPDOWN = recipeTable.GAS_BEGINRAMPDOWN,
                GAS_ENDRAMPDOWN = recipeTable.GAS_ENDRAMPDOWN,
                GAS_IDLECASTGAS = recipeTable.GAS_IDLECASTGAS,
                GAS_RUNCASTGAS = recipeTable.GAS_RUNCASTGAS,
                GAS_STARTCASTGAS = recipeTable.GAS_STARTCASTGAS,
                GAS_STARTCASTGASLEN = recipeTable.GAS_STARTCASTGASLEN,
                JET_OFFPRESLEN = recipeTable.JET_OFFPRESLEN,
                JET_OFFPRESLENEND = recipeTable.JET_OFFPRESLENEND,
                JET_PRES1 = recipeTable.JET_PRES1,
                JET_PRES1END = recipeTable.JET_PRES1END,
                JET_PRES2 = recipeTable.JET_PRES2,
                JET_PRES2END = recipeTable.JET_PRES2END,
                JET_PRESLEN1 = recipeTable.JET_PRESLEN1,
                JET_PRESLEN1END = recipeTable.JET_PRESLEN1END,
                JET_PRESLEN2 = recipeTable.JET_PRESLEN2,
                JET_PRESLEN2END = recipeTable.JET_PRESLEN2END,
                JET_STARTPRES = recipeTable.JET_STARTPRES,
                JET_STARTPRESEND = recipeTable.JET_STARTPRESEND,
                LEN_CASTLENGTH = recipeTable.LEN_CASTLENGTH,
                LUB_LEN2 = recipeTable.LUB_LEN2,
                LUB_LEN3 = recipeTable.LUB_LEN3,
                LUB_LEN4 = recipeTable.LUB_LEN4,
                LUB_PULSELUBECYCTIME = recipeTable.LUB_PULSELUBECYCTIME,
                LUB_PULSELUBECYCTIME2 = recipeTable.LUB_PULSELUBECYCTIME2,
                LUB_PULSELUBECYCTIME3 = recipeTable.LUB_PULSELUBECYCTIME3,
                LUB_PULSELUBECYCTIME4 = recipeTable.LUB_PULSELUBECYCTIME4,
                LUB_PULSELUBEOFFTIME = recipeTable.LUB_PULSELUBEOFFTIME,
                LUB_PULSELUBEONTIME = recipeTable.LUB_PULSELUBEONTIME,
                LUB_PULSELUBEPRESFIRE = recipeTable.LUB_PULSELUBEPRESFIRE,
                LUB_PULSELUBEPRESHOLD = recipeTable.LUB_PULSELUBEPRESHOLD,
                LUB_PULSELUBEPRESRESET = recipeTable.LUB_PULSELUBEPRESRESET,
                LUB_PULSELUBEPULSES = recipeTable.LUB_PULSELUBEPULSES,
                LUB_PULSELUBEPULSES2 = recipeTable.LUB_PULSELUBEPULSES2,
                LUB_PULSELUBEPULSES3 = recipeTable.LUB_PULSELUBEPULSES3,
                LUB_PULSELUBEPULSES4 = recipeTable.LUB_PULSELUBEPULSES4,
                MLC_FILLRATE1 = recipeTable.MLC_FILLRATE1,
                MLC_FILLRATE1STARTLEVEL = recipeTable.MLC_FILLRATE1STARTLEVEL,
                MLC_FILLRATE2 = recipeTable.MLC_FILLRATE2,
                MLC_FILLRATE2STARTLEVEL = recipeTable.MLC_FILLRATE2STARTLEVEL,
                MLC_FILLRATE3 = recipeTable.MLC_FILLRATE3,
                MLC_FILLRATE3STARTLEVEL = recipeTable.MLC_FILLRATE3STARTLEVEL,
                MLC_FILLRATE4 = recipeTable.MLC_FILLRATE4,
                MLC_FILLRATE4STARTLEVEL = recipeTable.MLC_FILLRATE4STARTLEVEL,
                MLC_FILLRATESTART = recipeTable.MLC_FILLRATESTART,
                MLC_MOLDLVL1 = recipeTable.MLC_MOLDLVL1,
                MLC_MOLDLVL1LEN = recipeTable.MLC_MOLDLVL1LEN,
                MLC_MOLDLVL2 = recipeTable.MLC_MOLDLVL2,
                MLC_MOLDLVL2LEN = recipeTable.MLC_MOLDLVL2LEN,
                MLC_MOLDLVL3 = recipeTable.MLC_MOLDLVL3,
                MLC_MOLDLVL3LEN = recipeTable.MLC_MOLDLVL3LEN,
                MLC_MOLDLVL4 = recipeTable.MLC_MOLDLVL4,
                MLC_MOLDLVL4LEN = recipeTable.MLC_MOLDLVL4LEN,
                MLC_MOLDLVL5 = recipeTable.MLC_MOLDLVL5,
                MLC_MOLDLVL5LEN = recipeTable.MLC_MOLDLVL5LEN,
                MLC_MOLDLVL6 = recipeTable.MLC_MOLDLVL6,
                MLC_MOLDLVL6LEN = recipeTable.MLC_MOLDLVL6LEN,
                MLC_MOLDLVL7 = recipeTable.MLC_MOLDLVL7,
                MLC_MOLDLVL7LEN = recipeTable.MLC_MOLDLVL7LEN,
                MLC_MOLDLVL8 = recipeTable.MLC_MOLDLVL8,
                MLC_MOLDLVL8LEN = recipeTable.MLC_MOLDLVL8LEN,
                MLC_MOLDLVL9 = recipeTable.MLC_MOLDLVL9,
                MLC_MOLDLVL9LEN = recipeTable.MLC_MOLDLVL9LEN,
                MLC_MOLDLVLSTART = recipeTable.MLC_MOLDLVLSTART,
                MLC_PINPRESET1 = recipeTable.MLC_PINPRESET1,
                MLC_PINPRESET2 = recipeTable.MLC_PINPRESET2,
                MLC_PINPRESET3 = recipeTable.MLC_PINPRESET3,
                MLC_PINPRESET4 = recipeTable.MLC_PINPRESET4,
                MLC_PINPRESET5 = recipeTable.MLC_PINPRESET5,
                MLC_PINPRESET6 = recipeTable.MLC_PINPRESET6,
                MLC_PINPRESET7 = recipeTable.MLC_PINPRESET7,
                MLC_PINPRESET8 = recipeTable.MLC_PINPRESET8,
                MLC_PINPRESET9 = recipeTable.MLC_PINPRESET9,
                MLC_PINPRESET10 = recipeTable.MLC_PINPRESET10,
                MLC_PINPRESET11 = recipeTable.MLC_PINPRESET11,
                MLC_PINPRESET12 = recipeTable.MLC_PINPRESET12,
                MLC_PINPRESET13 = recipeTable.MLC_PINPRESET13,
                MLC_PINPRESET14 = recipeTable.MLC_PINPRESET14,
                MLC_PINPRESET15 = recipeTable.MLC_PINPRESET15,
                MLC_UNCNTRLDFILLDIST = recipeTable.MLC_UNCNTRLDFILLDIST,
                MTL_DEGASTEMP = recipeTable.MTL_DEGASTEMP,
                ROD_RODSPEED = recipeTable.ROD_RODSPEED,
                SPD_CASTSPD1 = recipeTable.SPD_CASTSPD1,
                SPD_CASTSPD1LEN = recipeTable.SPD_CASTSPD1LEN,
                SPD_CASTSPD2 = recipeTable.SPD_CASTSPD2,
                SPD_CASTSPD2LEN = recipeTable.SPD_CASTSPD2LEN,
                SPD_CASTSPD3 = recipeTable.SPD_CASTSPD3,
                SPD_CASTSPD3LEN = recipeTable.SPD_CASTSPD3LEN,
                SPD_CASTSPD4 = recipeTable.SPD_CASTSPD4,
                SPD_CASTSPD4LEN = recipeTable.SPD_CASTSPD4LEN,
                SPD_CASTSPD5 = recipeTable.SPD_CASTSPD5,
                SPD_CASTSPD5LEN = recipeTable.SPD_CASTSPD5LEN,
                SPD_CASTSPD6 = recipeTable.SPD_CASTSPD6,
                SPD_CASTSPD6LEN = recipeTable.SPD_CASTSPD6LEN,
                SPD_CASTSPD7 = recipeTable.SPD_CASTSPD7,
                SPD_CASTSPD7LEN = recipeTable.SPD_CASTSPD7LEN,
                SPD_CASTSPD8 = recipeTable.SPD_CASTSPD8,
                SPD_CASTSPD8LEN = recipeTable.SPD_CASTSPD8LEN,
                SPD_CASTSPD9 = recipeTable.SPD_CASTSPD9,
                SPD_CASTSPD9LEN = recipeTable.SPD_CASTSPD9LEN,
                SPD_CASTSPDEND = recipeTable.SPD_CASTSPDEND,
                SPD_CASTSPDSTART = recipeTable.SPD_CASTSPDSTART,
                SPD_PLTNHOLDTIME = recipeTable.SPD_PLTNHOLDTIME,
                TGH_DAMPULLSP1 = recipeTable.TGH_DAMPULLSP1,
                TGH_DAMPULLSP2 = recipeTable.TGH_DAMPULLSP2,
                TGH_TROUGHTEMP = recipeTable.TGH_TROUGHTEMP,
                WIP_WiperOnLen = recipeTable.WIP_WiperOnLen,
                WIP_WiperPosition = recipeTable.WIP_WiperPosition,
                WIP_WIPPOS1 = recipeTable.WIP_WIPPOS1,
                WIP_WIPPOS1LEN = recipeTable.WIP_WIPPOS1LEN,
                WIP_WIPPOS2 = recipeTable.WIP_WIPPOS2,
                WIP_WIPPOS2LEN = recipeTable.WIP_WIPPOS2LEN,
                WIP_WIPPOS3 = recipeTable.WIP_WIPPOS3,
                WIP_WIPPOS3LEN = recipeTable.WIP_WIPPOS3LEN,
                WIP_WIPPOS4 = recipeTable.WIP_WIPPOS4,
                WIP_WIPPOS4LEN = recipeTable.WIP_WIPPOS4LEN,
                WIP_WIPPOS5 = recipeTable.WIP_WIPPOS5,
                WIP_WIPPOS5LEN = recipeTable.WIP_WIPPOS5LEN,
                WIP_WIPPOS6 = recipeTable.WIP_WIPPOS6,
                WIP_WIPPOS6LEN = recipeTable.WIP_WIPPOS6LEN,
                WIP_WIPPOS7 = recipeTable.WIP_WIPPOS7,
                WIP_WIPPOS7LEN = recipeTable.WIP_WIPPOS7LEN,
                WIP_WIPPOS8 = recipeTable.WIP_WIPPOS8,
                WIP_WIPPOS8LEN = recipeTable.WIP_WIPPOS8LEN,
                WIP_WIPPOS9 = recipeTable.WIP_WIPPOS9,
                WIP_WIPPOS9LEN = recipeTable.WIP_WIPPOS9LEN,
                WIP_WIPPOSEND = recipeTable.WIP_WIPPOSEND,
                WIP_WIPPOSSTART = recipeTable.WIP_WIPPOSSTART,
                WTR_WATEROFFDELAY = recipeTable.WTR_WATEROFFDELAY,
                WTR_WTRFLOW1 = recipeTable.WTR_WTRFLOW1,
                WTR_WTRFLOW1LEN = recipeTable.WTR_WTRFLOW1LEN,
                WTR_WTRFLOW2 = recipeTable.WTR_WTRFLOW2,
                WTR_WTRFLOW2LEN = recipeTable.WTR_WTRFLOW2LEN,
                WTR_WTRFLOW3 = recipeTable.WTR_WTRFLOW3,
                WTR_WTRFLOW3LEN = recipeTable.WTR_WTRFLOW3LEN,
                WTR_WTRFLOW4 = recipeTable.WTR_WTRFLOW4,
                WTR_WTRFLOW4LEN = recipeTable.WTR_WTRFLOW4LEN,
                WTR_WTRFLOW5 = recipeTable.WTR_WTRFLOW5,
                WTR_WTRFLOW5LEN = recipeTable.WTR_WTRFLOW5LEN,
                WTR_WTRFLOW6 = recipeTable.WTR_WTRFLOW6,
                WTR_WTRFLOW6LEN = recipeTable.WTR_WTRFLOW6LEN,
                WTR_WTRFLOW7 = recipeTable.WTR_WTRFLOW7,
                WTR_WTRFLOW7LEN = recipeTable.WTR_WTRFLOW7LEN,
                WTR_WTRFLOW8 = recipeTable.WTR_WTRFLOW8,
                WTR_WTRFLOW8LEN = recipeTable.WTR_WTRFLOW8LEN,
                WTR_WTRFLOW9 = recipeTable.WTR_WTRFLOW9,
                WTR_WTRFLOW9LEN = recipeTable.WTR_WTRFLOW9LEN,
                WTR_WTRFLOWEND = recipeTable.WTR_WTRFLOWEND,
                WTR_WTRFLOWSTART = recipeTable.WTR_WTRFLOWSTART,
                WTR_WTRTEMPHILIMIT = recipeTable.WTR_WTRTEMPHILIMIT,
                WTR_WTRTEMPLOLIMIT = recipeTable.WTR_WTRTEMPLOLIMIT,
                MSC_COOLDOWNTIME = recipeTable.MSC_COOLDOWNTIME,
                MSC_MOLDDIAMETER = recipeTable.MSC_MOLDDIAMETER,
                MSC_MOLDHEIGHT = recipeTable.MSC_MOLDHEIGHT,
                MSC_MOLDTHICKNESS = recipeTable.MSC_MOLDTHICKNESS,
                MSC_MOLDWIDTH = recipeTable.MSC_MOLDWIDTH,
                MSC_RECNAME = recipeTable.MSC_RECNAME,
                MSC_NUMBERMOLDS = recipeTable.MSC_NUMBERMOLDS,
                MSC_REV = recipeTable.MSC_REV,
                MSC_UserDef1 = recipeTable.MSC_UserDef1,
                MSC_UserDef2 = recipeTable.MSC_UserDef2,
                MSC_UserDef3 = recipeTable.MSC_UserDef3,
                MSC_UserDef4 = recipeTable.MSC_UserDef4,
                MSC_UserDef5 = recipeTable.MSC_UserDef5,
                MSC_UserDef6 = recipeTable.MSC_UserDef6,
                MSC_UserDef7 = recipeTable.MSC_UserDef7,
                MSC_UserDef8 = recipeTable.MSC_UserDef8,
                MSC_UserDef9 = recipeTable.MSC_UserDef9,
                MSC_UserDef10 = recipeTable.MSC_UserDef10,
                MSC_Description = recipeTable.MSC_Description,
                MSC_Alloy = recipeTable.MSC_Alloy,
                MSC_MoldTech = recipeTable.MSC_MoldTech,
                MSC_DateCreated = recipeTable.MSC_DateCreated,
                MSC_DateCreatedStr = recipeTable.MSC_DateCreatedStr,
                MSC_DateLastUsed = recipeTable.MSC_DateLastUsed,
                MSC_DateLastUsedStr = recipeTable.MSC_DateLastUsedStr,
                MSC_CreatedBy = recipeTable.MSC_CreatedBy,
                MSC_Creater = recipeTable.MSC_Creater,
                MSC_DateCreated_Start = recipeTable.MSC_DateCreated_Start,
                MSC_DateCreated_End = recipeTable.MSC_DateCreated_End,
                OrderNo = recipeTable.OrderNo,
                MSC_REVStr = recipeTable.MSC_REVStr,
                MSC_MOLDDIAMETERStr = recipeTable.MSC_MOLDDIAMETERStr,
                CastNumber = recipeTable.CastNumber,
                CastId = recipeTable.CastId,
                CastStartTime = recipeTable.CastStartTime,
                CastStartTimeStr = recipeTable.CastStartTimeStr,
                CastStopTime = recipeTable.CastStopTime,
                CastStopTimeStr = recipeTable.CastStopTimeStr,
                RepiceName = recipeTable.RepiceName,
                RepiceRevName = recipeTable.RepiceRevName,
                MSC_Type = recipeTable.MSC_Type
            };
            InitTag(ref recipeTableByVerification);
            return recipeTableByVerification;
        }

        /// <summary>
        /// 选择配方命令处理器
        /// </summary>
        /// <param name="obj"></param>
        private void SelectRecipeHandler(object obj)
        {
            for (int i = 0; i < DataCollection.Count; i++)
            {
                if (DataCollection[i].RecipeId == int.Parse(obj.ToString()))
                {
                    SelectRecipeModel = DataCollection[i];
                    break;
                }
            }
            PreselectionTable preselectionTable = new PreselectionTable
            {
                RecipeId = SelectRecipeModel.RecipeId
            };
            PreselectionTable deletePreselectionTable = new PreselectionTable();
            DapperToolsThisSystem.Delete<PreselectionTable>("DELETE PreselectionTable", deletePreselectionTable);
            if (DapperToolsThisSystem.Add<PreselectionTable>("INSERT INTO PreselectionTable(RecipeId) VALUES(@RecipeId);", preselectionTable) > 0)
            {
                Messenger.Default.Send<string>("RecipeSelectionPage", "GoToPage");
            }
        }
        /// <summary>
        /// 显示删除确认窗体命令处理器
        /// </summary>
        /// <param name="obj"></param>
        private void ShowDeleteModelHandler(object obj)
        {
            if (obj != null)
            {
                Messenger.Default.Send<string>(obj.ToString(), "SetDeleteRecipeId");
                WindowManager.ShowDialog("DeleteRecipeWindow", "");
            }
        }

        /// <summary>
        /// 跳转到编辑页面命令的处理器
        /// </summary>
        /// <param name="obj"></param>
        private void ShowEditModelHandler(object obj)
        {
            if (obj != null)
            {
                string QueryOneSql = @"SELECT a.RecipeId
                                             ,a.RecipeName
                                             ,a.MSC_REV
                                             ,a.MSC_MoldTech
                                             ,a.MSC_Alloy
                                             ,a.MSC_MOLDDIAMETER
                                             ,a.MSC_NUMBERMOLDS
                                             ,a.MSC_Description
                                             ,b.UserName as MSC_Creater
                                             ,CONVERT(NVARCHAR(255),a.MSC_DateCreated,120) AS MSC_DateCreatedStr
                                             ,CONVERT(NVARCHAR(255),a.MSC_DateLastUsed,120) AS MSC_DateLastUsedStr
                                             ,a.FRN_FRNBATHTEMPHILIM
                                             ,a.FRN_FRNBATHTEMPLOLIM
                                             ,a.FRN_FRNBATHTEMPSP
                                             ,a.FRN_FRNTILTBACKOFFSET
                                             ,a.GAS_BEGINRAMPDOWN
                                             ,a.GAS_ENDRAMPDOWN
                                             ,a.GAS_IDLECASTGAS
                                             ,a.GAS_RUNCASTGAS
                                             ,a.GAS_STARTCASTGAS
                                             ,a.GAS_STARTCASTGASLEN
                                             ,a.JET_OFFPRESLEN
                                             ,a.JET_OFFPRESLENEND
                                             ,a.JET_PRES1
                                             ,a.JET_PRES1END
                                             ,a.JET_PRES2
                                             ,a.JET_PRES2END
                                             ,a.JET_PRESLEN1
                                             ,a.JET_PRESLEN1END
                                             ,a.JET_PRESLEN2
                                             ,a.JET_PRESLEN2END
                                             ,a.JET_STARTPRES
                                             ,a.JET_STARTPRESEND
                                             ,a.LEN_CASTLENGTH
                                             ,a.LUB_LEN2
                                             ,a.LUB_LEN3
                                             ,a.LUB_LEN4
                                             ,a.LUB_PULSELUBECYCTIME
                                             ,a.LUB_PULSELUBECYCTIME2
                                             ,a.LUB_PULSELUBECYCTIME3
                                             ,a.LUB_PULSELUBECYCTIME4
                                             ,a.LUB_PULSELUBEOFFTIME
                                             ,a.LUB_PULSELUBEONTIME
                                             ,a.LUB_PULSELUBEPRESFIRE
                                             ,a.LUB_PULSELUBEPRESHOLD
                                             ,a.LUB_PULSELUBEPRESRESET
                                             ,a.LUB_PULSELUBEPULSES
                                             ,a.LUB_PULSELUBEPULSES2
                                             ,a.LUB_PULSELUBEPULSES3
                                             ,a.LUB_PULSELUBEPULSES4
                                             ,a.MLC_FILLRATE1
                                             ,a.MLC_FILLRATE1STARTLEVEL
                                             ,a.MLC_FILLRATE2
                                             ,a.MLC_FILLRATE2STARTLEVEL
                                             ,a.MLC_FILLRATE3
                                             ,a.MLC_FILLRATE3STARTLEVEL
                                             ,a.MLC_FILLRATE4
                                             ,a.MLC_FILLRATE4STARTLEVEL
                                             ,a.MLC_FILLRATESTART
                                             ,a.MLC_MOLDLVL1
                                             ,a.MLC_MOLDLVL1LEN
                                             ,a.MLC_MOLDLVL2
                                             ,a.MLC_MOLDLVL2LEN
                                             ,a.MLC_MOLDLVL3
                                             ,a.MLC_MOLDLVL3LEN
                                             ,a.MLC_MOLDLVL4
                                             ,a.MLC_MOLDLVL4LEN
                                             ,a.MLC_MOLDLVL5
                                             ,a.MLC_MOLDLVL5LEN
                                             ,a.MLC_MOLDLVL6
                                             ,a.MLC_MOLDLVL6LEN
                                             ,a.MLC_MOLDLVL7
                                             ,a.MLC_MOLDLVL7LEN
                                             ,a.MLC_MOLDLVL8
                                             ,a.MLC_MOLDLVL8LEN
                                             ,a.MLC_MOLDLVL9
                                             ,a.MLC_MOLDLVL9LEN
                                             ,a.MLC_MOLDLVLSTART
                                             ,a.MLC_PINPRESET1
                                             ,a.MLC_PINPRESET2
                                             ,a.MLC_PINPRESET3
                                             ,a.MLC_PINPRESET4
                                             ,a.MLC_PINPRESET5
                                             ,a.MLC_PINPRESET6
                                             ,a.MLC_PINPRESET7
                                             ,a.MLC_PINPRESET8
                                             ,a.MLC_PINPRESET9
                                             ,a.MLC_PINPRESET10
                                             ,a.MLC_PINPRESET11
                                             ,a.MLC_PINPRESET12
                                             ,a.MLC_PINPRESET13
                                             ,a.MLC_PINPRESET14
                                             ,a.MLC_PINPRESET15
                                             ,a.MLC_UNCNTRLDFILLDIST
                                             ,a.MTL_DEGASTEMP
                                             ,a.ROD_RODSPEED
                                             ,a.SPD_CASTSPD1
                                             ,a.SPD_CASTSPD1LEN
                                             ,a.SPD_CASTSPD2
                                             ,a.SPD_CASTSPD2LEN
                                             ,a.SPD_CASTSPD3
                                             ,a.SPD_CASTSPD3LEN
                                             ,a.SPD_CASTSPD4
                                             ,a.SPD_CASTSPD4LEN
                                             ,a.SPD_CASTSPD5
                                             ,a.SPD_CASTSPD5LEN
                                             ,a.SPD_CASTSPD6
                                             ,a.SPD_CASTSPD6LEN
                                             ,a.SPD_CASTSPD7
                                             ,a.SPD_CASTSPD7LEN
                                             ,a.SPD_CASTSPD8
                                             ,a.SPD_CASTSPD8LEN
                                             ,a.SPD_CASTSPD9
                                             ,a.SPD_CASTSPD9LEN
                                             ,a.SPD_CASTSPDEND
                                             ,a.SPD_CASTSPDSTART
                                             ,a.SPD_PLTNHOLDTIME
                                             ,a.TGH_DAMPULLSP1
                                             ,a.TGH_DAMPULLSP2
                                             ,a.TGH_TROUGHTEMP
                                             ,a.WIP_WiperOnLen
                                             ,a.WIP_WiperPosition
                                             ,a.WIP_WIPPOS1
                                             ,a.WIP_WIPPOS1LEN
                                             ,a.WIP_WIPPOS2
                                             ,a.WIP_WIPPOS2LEN
                                             ,a.WIP_WIPPOS3
                                             ,a.WIP_WIPPOS3LEN
                                             ,a.WIP_WIPPOS4
                                             ,a.WIP_WIPPOS4LEN
                                             ,a.WIP_WIPPOS5
                                             ,a.WIP_WIPPOS5LEN
                                             ,a.WIP_WIPPOS6
                                             ,a.WIP_WIPPOS6LEN
                                             ,a.WIP_WIPPOS7
                                             ,a.WIP_WIPPOS7LEN
                                             ,a.WIP_WIPPOS8
                                             ,a.WIP_WIPPOS8LEN
                                             ,a.WIP_WIPPOS9
                                             ,a.WIP_WIPPOS9LEN
                                             ,a.WIP_WIPPOSEND
                                             ,a.WIP_WIPPOSSTART
                                             ,a.WTR_WATEROFFDELAY
                                             ,a.WTR_WTRFLOW1
                                             ,a.WTR_WTRFLOW1LEN
                                             ,a.WTR_WTRFLOW2
                                             ,a.WTR_WTRFLOW2LEN
                                             ,a.WTR_WTRFLOW3
                                             ,a.WTR_WTRFLOW3LEN
                                             ,a.WTR_WTRFLOW4
                                             ,a.WTR_WTRFLOW4LEN
                                             ,a.WTR_WTRFLOW5
                                             ,a.WTR_WTRFLOW5LEN
                                             ,a.WTR_WTRFLOW6
                                             ,a.WTR_WTRFLOW6LEN
                                             ,a.WTR_WTRFLOW7
                                             ,a.WTR_WTRFLOW7LEN
                                             ,a.WTR_WTRFLOW8
                                             ,a.WTR_WTRFLOW8LEN
                                             ,a.WTR_WTRFLOW9
                                             ,a.WTR_WTRFLOW9LEN
                                             ,a.WTR_WTRFLOWEND
                                             ,a.WTR_WTRFLOWSTART
                                             ,a.WTR_WTRTEMPHILIMIT
                                             ,a.WTR_WTRTEMPLOLIMIT
                                             ,a.MSC_COOLDOWNTIME
                                             ,a.MSC_MOLDHEIGHT
                                             ,a.MSC_MOLDTHICKNESS
                                             ,a.MSC_MOLDWIDTH
                                             ,a.MSC_RECNAME
                                             ,a.MSC_UserDef1
                                             ,a.MSC_UserDef2
                                             ,a.MSC_UserDef3
                                             ,a.MSC_UserDef4
                                             ,a.MSC_UserDef5
                                             ,a.MSC_UserDef6
                                             ,a.MSC_UserDef7
                                             ,a.MSC_UserDef8
                                             ,a.MSC_UserDef9
                                             ,a.MSC_UserDef10
                                             ,a.MSC_Type
                                     FROM RecipeTable a
                                     LEFT JOIN [User] b ON a.MSC_CreatedBy = b.UserId WHERE a.RecipeId = @RecipeId ";
                RecipeTableByVerification QueryModel = new RecipeTableByVerification();
                QueryModel.RecipeId = int.Parse(obj.ToString());
                SystemConfig._EditModel = DapperToolsThisSystem.Query<RecipeTableByVerification>(QueryOneSql, QueryModel);
                Messenger.Default.Send("", "Refresh");
                Messenger.Default.Send("EditRecipePage", "GoToPage");
            }
        }
        /// <summary>
        /// 创建命令处理器
        /// </summary>
        /// <param name="obj"></param>
        private void CreateHandler(object obj)
        {
            Messenger.Default.Send<string>("CreateRecipePage", "GoToPage");
        }
        /// <summary>
        /// 搜索命令处理器
        /// </summary>
        /// <param name="obj"></param>
        private void SeachHandler(object obj)
        {
            QueryDataCollection();
        }

        /// <summary>
        /// 打开更改页码窗体
        /// </summary>
        /// <param name="obj"></param>
        private void ChangeCurrentPageNumberHandler(object obj)
        {
            PageNumers = new ObservableCollection<PageNumerModel>();
            for (int i = 0; i < TotalPageNumber; i++)
            {
                PageNumers.Add(new PageNumerModel() { PageNumberStr = (i + 1).ToString() });
            }
            if (PageNumers.Count > 1)
            {
                WindowManager.ShowDialog("AllPageNumberPanel", "");
            }
        }

        /// <summary>
        /// 跳转到更改页码的列表
        /// </summary>
        /// <param name="obj"></param>
        private void GoToPageByNumberAndCloseAllPageNumberPanelHandler(object obj)
        {
            GoToPageByNumberHandler(obj);
            Messenger.Default.Send<NotificationMessage>(new NotificationMessage(this, "HideAllPageNumberPanel"));
        }


        /// <summary>
        /// 跳转到指定页面命令的处理器
        /// </summary>
        /// <param name="obj"></param>
        private void GoToPageByNumberHandler(object obj)
        {
            switch (obj.ToString())
            {
                case "PreviousPage":
                    CurrentPageNumber = PreviousPageNumber;
                    break;
                case "NextPage":
                    CurrentPageNumber = NextPageNumber;
                    break;
                case "FirstPage":
                    CurrentPageNumber = 1;
                    break;
                case "LastPage":
                    CurrentPageNumber = TotalPageNumber;
                    break;
                default:
                    CurrentPageNumber = int.Parse(obj.ToString());
                    break;
            }
            QueryDataCollection();
        }

        /// <summary>
        /// 显示配方选择页面命令的处理器
        /// </summary>
        /// <param name="obj"></param>
        private void ShowSelectPageHandler(object obj)
        {
            //加载最近使用配方条件列表
            string sql = @"SELECT  
                                  a.RecipeName
                           FROM RecipeTable a
                           GROUP BY a.RecipeName";
            RecentlyUsedRecipes = DapperToolsThisSystem.QueryOc<RecipeTable>(sql);

            //加载合金条件列表
            sql = @"SELECT b.MSC_Alloy
                    FROM RecipeTable b 
                    GROUP BY b.MSC_Alloy";
            Alloys = DapperToolsThisSystem.QueryOc<RecipeTable>(sql);
            //加载工艺条件列表
            sql = @"SELECT b.MSC_MoldTech
                    FROM RecipeTable b 
                    GROUP BY b.MSC_MoldTech";
            MoldTechs = DapperToolsThisSystem.QueryOc<RecipeTable>(sql);
            //加载直径条件列表
            sql = @"SELECT b.MSC_MOLDDIAMETER as MSC_MOLDDIAMETERStr
                    FROM RecipeTable b 
                    GROUP BY b.MSC_MOLDDIAMETER";
            MoldDiameters = DapperToolsThisSystem.QueryOc<RecipeTable>(sql);
            QueryDataCollection();
            //跳转到配方选择页面
            Messenger.Default.Send<string>("RecipeSelectionListPage", "GoToPage");
        }
        /// <summary>
        /// 添加或删除配方名称条件命令处理器
        /// </summary>
        /// <param name="obj"></param>
        private void AddRecipeNameConditionsHandler(object obj)
        {
            if (obj != null)
            {
                bool IsHave = false;

                for (int i = 0; i < RecipeNameConditions.Count; i++)
                {
                    if (RecipeNameConditions[i] == obj.ToString())
                    {
                        IsHave = true;
                        break;
                    }
                }
                if (IsHave)
                {
                    RecipeNameConditions.Remove(obj.ToString());
                }
                else
                {
                    RecipeNameConditions.Add(obj.ToString());
                }
                QueryDataCollection();
            }
        }
        /// <summary>
        /// 添加或删除合金条件命令处理器
        /// </summary>
        /// <param name="obj"></param>
        private void AddAlloyConditionsHandler(object obj)
        {
            if (obj != null)
            {
                bool IsHave = false;

                for (int i = 0; i < AlloyConditions.Count; i++)
                {
                    if (AlloyConditions[i] == obj.ToString())
                    {
                        IsHave = true;
                        break;
                    }
                }
                if (IsHave)
                {
                    AlloyConditions.Remove(obj.ToString());
                }
                else
                {
                    AlloyConditions.Add(obj.ToString());
                }
                QueryDataCollection();
            }
        }
        /// <summary>
        /// 添加或删除工艺条件命令处理器
        /// </summary>
        /// <param name="obj"></param>
        private void AddMoldTechConditionsHandler(object obj)
        {
            if (obj != null)
            {
                bool IsHave = false;

                for (int i = 0; i < MoldTechConditions.Count; i++)
                {
                    if (MoldTechConditions[i] == obj.ToString())
                    {
                        IsHave = true;
                        break;
                    }
                }
                if (IsHave)
                {
                    MoldTechConditions.Remove(obj.ToString());
                }
                else
                {
                    MoldTechConditions.Add(obj.ToString());
                }
                QueryDataCollection();
            }
        }
        /// <summary>
        /// 添加或删除直径条件命令处理器
        /// </summary>
        /// <param name="obj"></param>
        private void AddMoldDiametersConditionsHandler(object obj)
        {
            if (obj != null)
            {
                bool IsHave = false;

                for (int i = 0; i < MoldDiametersConditions.Count; i++)
                {
                    if (MoldDiametersConditions[i] == obj.ToString())
                    {
                        IsHave = true;
                        break;
                    }
                }
                if (IsHave)
                {
                    MoldDiametersConditions.Remove(obj.ToString());
                }
                else
                {
                    MoldDiametersConditions.Add(obj.ToString());
                }
                QueryDataCollection();
            }
        }
        #endregion 声明命令

        #region 声明搜索条件集合
        /// <summary>
        /// 搜索条件配方名称
        /// </summary>
        private string _RecipeName;
        /// <summary>
        /// 搜索条件配方名称
        /// </summary>
        public string RecipeName
        {
            get { return _RecipeName; }
            set
            {
                _RecipeName = value;
                RaisePropertyChanged("RecipeName");
            }
        }


        /// <summary>
        /// 配方搜索条件
        /// </summary>
        private List<string> _RecipeNameConditions = new List<string>();
        /// <summary>
        /// 配方搜索条件
        /// </summary>
        public List<string> RecipeNameConditions
        {
            get { return _RecipeNameConditions; }
            set
            {
                _RecipeNameConditions = value;
                RaisePropertyChanged("RecipeNameConditions");
            }
        }

        /// <summary>
        /// 合金搜索条件
        /// </summary>
        private List<string> _AlloyConditions = new List<string>();
        /// <summary>
        /// 合金搜索条件
        /// </summary>
        public List<string> AlloyConditions
        {
            get { return _AlloyConditions; }
            set
            {
                _AlloyConditions = value;
                RaisePropertyChanged("AlloyConditions");
            }
        }
        /// <summary>
        /// 工艺搜索条件
        /// </summary>
        private List<string> _MoldTechConditions = new List<string>();
        /// <summary>
        /// 工艺搜索条件
        /// </summary>
        public List<string> MoldTechConditions
        {
            get { return _MoldTechConditions; }
            set
            {
                _MoldTechConditions = value;
                RaisePropertyChanged("MoldTechConditions");
            }
        }
        /// <summary>
        /// 直径搜索条件
        /// </summary>
        private List<string> _MoldDiametersConditions = new List<string>();
        /// <summary>
        /// 直径搜索条件
        /// </summary>
        public List<string> MoldDiametersConditions
        {
            get { return _MoldDiametersConditions; }
            set
            {
                _MoldDiametersConditions = value;
                RaisePropertyChanged("MoldDiametersConditions");
            }
        }
        #endregion 声明搜索条件集合
        /// <summary>
        /// 当前搜索结果集合
        /// </summary>
        private ObservableCollection<RecipeTable> _DataCollection = new ObservableCollection<RecipeTable>();
        /// <summary>
        /// 当前搜索结果集合
        /// </summary>
        public ObservableCollection<RecipeTable> DataCollection
        {
            get { return _DataCollection; }
            set
            {
                _DataCollection = value;
                RaisePropertyChanged("DataCollection");
            }
        }

        private static Brush RedBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFF0000"));

        private static Brush GreenBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF18C500"));

        private Brush _Button_InputNormal = RedBrush;

        public Brush Button_InputNormal
        {
            get { return _Button_InputNormal; }
            set
            {
                _Button_InputNormal = value;
                RaisePropertyChanged("Button_InputNormal");
            }
        }
        private Brush _Button_RecipeValid = RedBrush;
        public Brush Button_RecipeValid
        {
            get { return _Button_RecipeValid; }
            set
            {
                _Button_RecipeValid = value;
                RaisePropertyChanged("Button_RecipeValid");
            }
        }
        private Brush _Button_Accepted = RedBrush;
        public Brush Button_Accepted
        {
            get { return _Button_Accepted; }
            set
            {
                _Button_Accepted = value;
                RaisePropertyChanged("Button_Accepted");
            }
        }
        /// <summary>
        /// 颜色转换
        /// </summary>
        /// <param name="htmlcolor"></param>
        /// <returns></returns>
        private static SolidColorBrush ConvertToBrush(string htmlcolor)
        {
            if (htmlcolor != null)
            {
                Color color = (Color)System.Windows.Media.ColorConverter.ConvertFromString(htmlcolor);
                return new SolidColorBrush(color);
            }
            return null;
        }
        #region 快速筛选搜索条件的数据
        /// <summary>
        /// 最近使用的配方列表
        /// </summary>
        private ObservableCollection<RecipeTable> _RecentlyUsedRecipes = new ObservableCollection<RecipeTable>();
        /// <summary>
        /// 最近使用的配方列表
        /// </summary>
        public ObservableCollection<RecipeTable> RecentlyUsedRecipes
        {
            get { return _RecentlyUsedRecipes; }
            set
            {
                _RecentlyUsedRecipes = value;
                RaisePropertyChanged("RecentlyUsedRecipes");
            }
        }

        /// <summary>
        /// 合金条件列表
        /// </summary>
        private ObservableCollection<RecipeTable> _Alloys = new ObservableCollection<RecipeTable>();
        /// <summary>
        /// 合金条件列表
        /// </summary>
        public ObservableCollection<RecipeTable> Alloys
        {
            get { return _Alloys; }
            set
            {
                _Alloys = value;
                RaisePropertyChanged("Alloys");
            }
        }

        /// <summary>
        /// 工艺条件列表
        /// </summary>
        private ObservableCollection<RecipeTable> _MoldTechs = new ObservableCollection<RecipeTable>();
        /// <summary>
        /// 工艺条件列表
        /// </summary>
        public ObservableCollection<RecipeTable> MoldTechs
        {
            get { return _MoldTechs; }
            set
            {
                _MoldTechs = value;
                RaisePropertyChanged("MoldTechs");
            }
        }

        /// <summary>
        /// 直径条件列表
        /// </summary>
        private ObservableCollection<RecipeTable> _MoldDiameters = new ObservableCollection<RecipeTable>();
        /// <summary>
        /// 直径条件列表
        /// </summary>
        public ObservableCollection<RecipeTable> MoldDiameters
        {
            get { return _MoldDiameters; }
            set
            {
                _MoldDiameters = value;
                RaisePropertyChanged("MoldDiameters");

            }
        }
        #endregion 快速筛选搜索条件的数据
        /// <summary>
        /// 构造方法
        /// </summary>
        public RecipeSelectionPageViewModel()
        {
            InitCommand();
            QueryDataCollection();
            RecipeTable recipeTable = new RecipeTable();
            PreselectionTable preselectionTable = new PreselectionTable();
            PreselectionTable result = DapperToolsThisSystem.Query<PreselectionTable>("SELECT TOP 1 * FROM PreselectionTable", preselectionTable);
            if (result != null)
            {
                recipeTable.RecipeId = result.RecipeId;
                SelectRecipeModel = DapperToolsThisSystem.Query<RecipeTable>("SELECT * FROM RecipeTable WHERE RecipeId = @RecipeId", recipeTable);
            }

            //刷新数据
            Messenger.Default.Register<string>(this, "RecipeSelectionPageRefurbish", (message) =>
            {
                ShowSelectPageCommand.Execute(message);
            });

            //设置预选配方
            Messenger.Default.Register<int>(this, "SetPreSelectRecipe", (RecipeId) =>
            {
                string QueryOneSql = @"SELECT a.RecipeId
                                             ,a.RecipeName
                                             ,a.MSC_REV
                                             ,a.MSC_MoldTech
                                             ,a.MSC_Alloy
                                             ,a.MSC_MOLDDIAMETER
                                             ,a.MSC_NUMBERMOLDS
                                             ,a.MSC_Description
                                             ,b.UserName as MSC_Creater
                                             ,CONVERT(NVARCHAR(255),a.MSC_DateCreated,120) AS MSC_DateCreatedStr
                                             ,CONVERT(NVARCHAR(255),a.MSC_DateLastUsed,120) AS MSC_DateLastUsedStr
                                             ,a.FRN_FRNBATHTEMPHILIM
                                             ,a.FRN_FRNBATHTEMPLOLIM
                                             ,a.FRN_FRNBATHTEMPSP
                                             ,a.FRN_FRNTILTBACKOFFSET
                                             ,a.GAS_BEGINRAMPDOWN
                                             ,a.GAS_ENDRAMPDOWN
                                             ,a.GAS_IDLECASTGAS
                                             ,a.GAS_RUNCASTGAS
                                             ,a.GAS_STARTCASTGAS
                                             ,a.GAS_STARTCASTGASLEN
                                             ,a.JET_OFFPRESLEN
                                             ,a.JET_OFFPRESLENEND
                                             ,a.JET_PRES1
                                             ,a.JET_PRES1END
                                             ,a.JET_PRES2
                                             ,a.JET_PRES2END
                                             ,a.JET_PRESLEN1
                                             ,a.JET_PRESLEN1END
                                             ,a.JET_PRESLEN2
                                             ,a.JET_PRESLEN2END
                                             ,a.JET_STARTPRES
                                             ,a.JET_STARTPRESEND
                                             ,a.LEN_CASTLENGTH
                                             ,a.LUB_LEN2
                                             ,a.LUB_LEN3
                                             ,a.LUB_LEN4
                                             ,a.LUB_PULSELUBECYCTIME
                                             ,a.LUB_PULSELUBECYCTIME2
                                             ,a.LUB_PULSELUBECYCTIME3
                                             ,a.LUB_PULSELUBECYCTIME4
                                             ,a.LUB_PULSELUBEOFFTIME
                                             ,a.LUB_PULSELUBEONTIME
                                             ,a.LUB_PULSELUBEPRESFIRE
                                             ,a.LUB_PULSELUBEPRESHOLD
                                             ,a.LUB_PULSELUBEPRESRESET
                                             ,a.LUB_PULSELUBEPULSES
                                             ,a.LUB_PULSELUBEPULSES2
                                             ,a.LUB_PULSELUBEPULSES3
                                             ,a.LUB_PULSELUBEPULSES4
                                             ,a.MLC_FILLRATE1
                                             ,a.MLC_FILLRATE1STARTLEVEL
                                             ,a.MLC_FILLRATE2
                                             ,a.MLC_FILLRATE2STARTLEVEL
                                             ,a.MLC_FILLRATE3
                                             ,a.MLC_FILLRATE3STARTLEVEL
                                             ,a.MLC_FILLRATE4
                                             ,a.MLC_FILLRATE4STARTLEVEL
                                             ,a.MLC_FILLRATESTART
                                             ,a.MLC_MOLDLVL1
                                             ,a.MLC_MOLDLVL1LEN
                                             ,a.MLC_MOLDLVL2
                                             ,a.MLC_MOLDLVL2LEN
                                             ,a.MLC_MOLDLVL3
                                             ,a.MLC_MOLDLVL3LEN
                                             ,a.MLC_MOLDLVL4
                                             ,a.MLC_MOLDLVL4LEN
                                             ,a.MLC_MOLDLVL5
                                             ,a.MLC_MOLDLVL5LEN
                                             ,a.MLC_MOLDLVL6
                                             ,a.MLC_MOLDLVL6LEN
                                             ,a.MLC_MOLDLVL7
                                             ,a.MLC_MOLDLVL7LEN
                                             ,a.MLC_MOLDLVL8
                                             ,a.MLC_MOLDLVL8LEN
                                             ,a.MLC_MOLDLVL9
                                             ,a.MLC_MOLDLVL9LEN
                                             ,a.MLC_MOLDLVLSTART
                                             ,a.MLC_PINPRESET1
                                             ,a.MLC_PINPRESET2
                                             ,a.MLC_PINPRESET3
                                             ,a.MLC_PINPRESET4
                                             ,a.MLC_PINPRESET5
                                             ,a.MLC_PINPRESET6
                                             ,a.MLC_PINPRESET7
                                             ,a.MLC_PINPRESET8
                                             ,a.MLC_PINPRESET9
                                             ,a.MLC_PINPRESET10
                                             ,a.MLC_PINPRESET11
                                             ,a.MLC_PINPRESET12
                                             ,a.MLC_PINPRESET13
                                             ,a.MLC_PINPRESET14
                                             ,a.MLC_PINPRESET15
                                             ,a.MLC_UNCNTRLDFILLDIST
                                             ,a.MTL_DEGASTEMP
                                             ,a.ROD_RODSPEED
                                             ,a.SPD_CASTSPD1
                                             ,a.SPD_CASTSPD1LEN
                                             ,a.SPD_CASTSPD2
                                             ,a.SPD_CASTSPD2LEN
                                             ,a.SPD_CASTSPD3
                                             ,a.SPD_CASTSPD3LEN
                                             ,a.SPD_CASTSPD4
                                             ,a.SPD_CASTSPD4LEN
                                             ,a.SPD_CASTSPD5
                                             ,a.SPD_CASTSPD5LEN
                                             ,a.SPD_CASTSPD6
                                             ,a.SPD_CASTSPD6LEN
                                             ,a.SPD_CASTSPD7
                                             ,a.SPD_CASTSPD7LEN
                                             ,a.SPD_CASTSPD8
                                             ,a.SPD_CASTSPD8LEN
                                             ,a.SPD_CASTSPD9
                                             ,a.SPD_CASTSPD9LEN
                                             ,a.SPD_CASTSPDEND
                                             ,a.SPD_CASTSPDSTART
                                             ,a.SPD_PLTNHOLDTIME
                                             ,a.TGH_DAMPULLSP1
                                             ,a.TGH_DAMPULLSP2
                                             ,a.TGH_TROUGHTEMP
                                             ,a.WIP_WiperOnLen
                                             ,a.WIP_WiperPosition
                                             ,a.WIP_WIPPOS1
                                             ,a.WIP_WIPPOS1LEN
                                             ,a.WIP_WIPPOS2
                                             ,a.WIP_WIPPOS2LEN
                                             ,a.WIP_WIPPOS3
                                             ,a.WIP_WIPPOS3LEN
                                             ,a.WIP_WIPPOS4
                                             ,a.WIP_WIPPOS4LEN
                                             ,a.WIP_WIPPOS5
                                             ,a.WIP_WIPPOS5LEN
                                             ,a.WIP_WIPPOS6
                                             ,a.WIP_WIPPOS6LEN
                                             ,a.WIP_WIPPOS7
                                             ,a.WIP_WIPPOS7LEN
                                             ,a.WIP_WIPPOS8
                                             ,a.WIP_WIPPOS8LEN
                                             ,a.WIP_WIPPOS9
                                             ,a.WIP_WIPPOS9LEN
                                             ,a.WIP_WIPPOSEND
                                             ,a.WIP_WIPPOSSTART
                                             ,a.WTR_WATEROFFDELAY
                                             ,a.WTR_WTRFLOW1
                                             ,a.WTR_WTRFLOW1LEN
                                             ,a.WTR_WTRFLOW2
                                             ,a.WTR_WTRFLOW2LEN
                                             ,a.WTR_WTRFLOW3
                                             ,a.WTR_WTRFLOW3LEN
                                             ,a.WTR_WTRFLOW4
                                             ,a.WTR_WTRFLOW4LEN
                                             ,a.WTR_WTRFLOW5
                                             ,a.WTR_WTRFLOW5LEN
                                             ,a.WTR_WTRFLOW6
                                             ,a.WTR_WTRFLOW6LEN
                                             ,a.WTR_WTRFLOW7
                                             ,a.WTR_WTRFLOW7LEN
                                             ,a.WTR_WTRFLOW8
                                             ,a.WTR_WTRFLOW8LEN
                                             ,a.WTR_WTRFLOW9
                                             ,a.WTR_WTRFLOW9LEN
                                             ,a.WTR_WTRFLOWEND
                                             ,a.WTR_WTRFLOWSTART
                                             ,a.WTR_WTRTEMPHILIMIT
                                             ,a.WTR_WTRTEMPLOLIMIT
                                             ,a.MSC_COOLDOWNTIME
                                             ,a.MSC_MOLDHEIGHT
                                             ,a.MSC_MOLDTHICKNESS
                                             ,a.MSC_MOLDWIDTH
                                             ,a.MSC_RECNAME
                                             ,a.MSC_UserDef1
                                             ,a.MSC_UserDef2
                                             ,a.MSC_UserDef3
                                             ,a.MSC_UserDef4
                                             ,a.MSC_UserDef5
                                             ,a.MSC_UserDef6
                                             ,a.MSC_UserDef7
                                             ,a.MSC_UserDef8
                                             ,a.MSC_UserDef9
                                             ,a.MSC_UserDef10
                                             ,a.MSC_Type
                                     FROM RecipeTable a
                                     LEFT JOIN [User] b ON a.MSC_CreatedBy = b.UserId WHERE a.RecipeId = @RecipeId ";
                RecipeTableByVerification QueryModel = new RecipeTableByVerification();
                QueryModel.RecipeId = RecipeId;
                SelectRecipeModel = DapperToolsThisSystem.Query<RecipeTableByVerification>(QueryOneSql, QueryModel);
                PreselectionTable deletePreselectionTable = new PreselectionTable();
                PreselectionTable preselectionTable1 = new PreselectionTable
                {
                    RecipeId = SelectRecipeModel.RecipeId
                };
                DapperToolsThisSystem.Delete<PreselectionTable>("DELETE PreselectionTable", deletePreselectionTable);
                if (DapperToolsThisSystem.Add<PreselectionTable>("INSERT INTO PreselectionTable(RecipeId) VALUES(@RecipeId);", preselectionTable1) > 0)
                {
                    Messenger.Default.Send<string>("RecipeSelectionPage", "GoToPage");
                }
            });
            RecipeName = "请输入配方名称";
        }



        /// <summary>
        /// 搜索配方列表数据
        /// </summary>
        private void QueryDataCollection()
        {
            string baseSearchSql = @"SELECT ROW_NUMBER() OVER (
                                                                ORDER BY MSC_DateCreated DESC
                                                               ) as rownumber,
                                            a.*
                                     FROM RecipeTable a
                                     WHERE 1 = 1
                                     " + GetConditionalSql();

            string pageingSql = @"SELECT TOP " + itemCount + @" * 
                                  FROM (" + baseSearchSql + @") temp_row
                                  WHERE rownumber > ((" + CurrentPageNumber + @" - 1 ) * " + itemCount + @" ); ";


            DataCollection = DapperToolsThisSystem.QueryOc<RecipeTable>(pageingSql);
            //总数据量
            TotalDataCount = DapperToolsThisSystem.GetCount(baseSearchSql);

            for (int i = 0; i < DataCollection.Count; i++)
            {
                DataCollection[i].OrderNo = (i + 1);
            }
        }
        /// <summary>
        /// 获取条件语句
        /// </summary>
        /// <returns></returns>
        private string GetConditionalSql()
        {
            string ConditionalSql = "";
            if (RecipeNameConditions.Count > 0)
            {
                ConditionalSql += " AND (";
                for (int i = 0; i < RecipeNameConditions.Count; i++)
                {
                    if (i > 0)
                    {
                        ConditionalSql += " OR RecipeName = '" + RecipeNameConditions[i] + "'";
                    }
                    else
                    {
                        ConditionalSql += " RecipeName = '" + RecipeNameConditions[i] + "'";
                    }

                }
                ConditionalSql += " ) ";
            }
            if (AlloyConditions.Count > 0)
            {
                ConditionalSql += " AND (";
                for (int i = 0; i < AlloyConditions.Count; i++)
                {
                    if (i > 0)
                    {
                        ConditionalSql += " OR MSC_Alloy = '" + AlloyConditions[i] + "'";
                    }
                    else
                    {
                        ConditionalSql += " MSC_Alloy = '" + AlloyConditions[i] + "'";
                    }

                }
                ConditionalSql += " ) ";
            }
            if (MoldTechConditions.Count > 0)
            {
                ConditionalSql += " AND (";
                for (int i = 0; i < MoldTechConditions.Count; i++)
                {
                    if (i > 0)
                    {
                        ConditionalSql += " OR MSC_MoldTech = '" + MoldTechConditions[i] + "'";
                    }
                    else
                    {
                        ConditionalSql += " MSC_MoldTech = '" + MoldTechConditions[i] + "'";
                    }

                }
                ConditionalSql += " ) ";
            }
            if (MoldDiametersConditions.Count > 0)
            {
                ConditionalSql += " AND (";
                for (int i = 0; i < MoldDiametersConditions.Count; i++)
                {
                    if (i > 0)
                    {
                        ConditionalSql += " OR MSC_MOLDDIAMETER = " + MoldDiametersConditions[i] + "";
                    }
                    else
                    {
                        ConditionalSql += " MSC_MOLDDIAMETER = " + MoldDiametersConditions[i] + "";
                    }

                }
                ConditionalSql += " ) ";
            }
            if (RecipeName != null && RecipeName.Trim() != "" && RecipeName.Trim() != "请输入配方名称")
            {
                ConditionalSql += " AND RecipeName LIKE '%" + RecipeName + "%'";
            }
            return ConditionalSql;
        }



    }
}
